Skip to content
Permalink
Browse files Browse the repository at this point in the history
X3F: check huffman tree size
  • Loading branch information
alextutubalin committed Apr 4, 2020
1 parent d75af00 commit 11c4db2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/x3f_tools.h
Expand Up @@ -213,6 +213,7 @@ typedef struct x3f_huffnode_s
typedef struct x3f_hufftree_s
{
uint32_t free_node_index; /* Free node index in huffman tree array */
uint32_t total_node_index;
x3f_huffnode_t *nodes; /* Coding tree */
} x3f_hufftree_t;

Expand Down
3 changes: 3 additions & 0 deletions src/x3f/x3f_utils_patched.cpp
Expand Up @@ -179,6 +179,7 @@ static void new_huffman_tree(x3f_hufftree_t *HTP, int bits)
int leaves = 1 << bits;

HTP->free_node_index = 0;
HTP->total_node_index = HUF_TREE_MAX_NODES(leaves);
HTP->nodes = (x3f_huffnode_t *)calloc(1, HUF_TREE_MAX_NODES(leaves) *
sizeof(x3f_huffnode_t));
}
Expand Down Expand Up @@ -708,6 +709,8 @@ static char *display_code(int length, uint32_t code, char *buffer)

static x3f_huffnode_t *new_node(x3f_hufftree_t *tree)
{
if (tree->free_node_index >= tree->total_node_index)
throw LIBRAW_EXCEPTION_IO_CORRUPT;
x3f_huffnode_t *t = &tree->nodes[tree->free_node_index];

t->branch[0] = NULL;
Expand Down

0 comments on commit 11c4db2

Please sign in to comment.