Skip to content

fix(cgif_rgb): add NULL checks after allocations#98

Closed
uwezkhan wants to merge 1 commit into
dloebl:mainfrom
uwezkhan:fix/null-checks-memory-allocation
Closed

fix(cgif_rgb): add NULL checks after allocations#98
uwezkhan wants to merge 1 commit into
dloebl:mainfrom
uwezkhan:fix/null-checks-memory-allocation

Conversation

@uwezkhan

Copy link
Copy Markdown
Contributor

fix(cgif_rgb): add NULL checks after allocations

Add missing NULL pointer checks after malloc/realloc calls to prevent
crashes on memory allocation failures. This fixes critical security
vulnerabilities where NULL pointers were dereferenced without checking.

Functions modified:

  • init_col_hash_table: Check malloc return value
  • resize_col_hash_table: Check realloc and malloc return values
  • hash_to_dense: Check malloc return value
  • new_tree_node: Check malloc return value
  • quantize_and_dither: Check malloc, cleanup decision tree on failure
  • cgif_rgb_newgif: Check malloc return value
  • cgif_rgb_addframe: Check malloc twice, cleanup on failure

Impact:

  • Prevents guaranteed crashes in low-memory conditions
  • Properly propagates CGIF_EALLOC error code
  • Adds cleanup for partially allocated memory
  • No changes to success path or API

Fixes: CWE-476 (NULL Pointer Dereference)
Total: 7 functions fixed, 31 lines added

@uwezkhan

Copy link
Copy Markdown
Contributor Author

Hey i have added a PR please check

@uwezkhan uwezkhan closed this Feb 21, 2026
@uwezkhan
uwezkhan deleted the fix/null-checks-memory-allocation branch February 21, 2026 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant