fix(ocr): add NULL checks and fix memory leaks#1798
Merged
Conversation
This commit addresses multiple memory safety issues in ccx_encoders_spupng.c: **NULL pointer dereference fixes (crash prevention):** 1. write_cc_bitmap_as_spupng() line 440: Added NULL check after malloc for pbuf - previously would crash on memset if allocation failed. 2. write_image() line 541: Added NULL check after malloc for row buffer with proper cleanup via goto finalise. 3. center_justify() line 611: Added NULL check after malloc for temp_buffer - previously would crash immediately on use. 4. utf8_to_utf32() line 718: Added NULL check after calloc for string_utf32 - previously would crash on use by iconv. 5. spupng_export_string2png() line 780: Fixed existing NULL check that printed error but did not return/exit - code would continue to memset(NULL, ...) causing a crash. **Memory leak fixes:** 6. spupng_export_string2png() line 789: Fixed leak where buffer was not freed when strdup(str) failed and function returned early. 7. spupng_export_string2png() line 901: Fixed leak on realloc failure where buffer, tmp, and string_utf32 were leaked. Now properly frees all three before calling fatal(). All fatal() calls include diagnostic information (function name and bytes requested where applicable) to aid debugging OOM conditions. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- search_language_pack: add NULL check after strdup(), fix unsafe realloc() that lost original pointer on failure - init_ocr: fix memory leak where ctx wasn't freed on early return when tessdata not found, add NULL checks for strdup() calls - ocr_bitmap: fix memory leak when pixCreate partially fails, add missing boxDestroy for crop_points on early return, add NULL checks for histogram/iot/mcit allocations, fix unsafe realloc() calls, add NULL check for text_out strdup - ocr_rect: add NULL check for copy allocation, initialize copy->data to NULL to prevent freep on uninitialized pointer, add NULL check for copy->data allocation - paraof_ocrtext: use fatal() on malloc failure for consistent OOM handling All OOM conditions now use fatal(EXIT_NOT_ENOUGH_MEMORY, ...) following the project's coding patterns. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
e281cc9 to
1342e4e
Compare
Collaborator
CCExtractor CI platform finished running the test files on linux. Below is a summary of the test results, when compared to test for commit 77e1dff...:
NOTE: The following tests have been failing on the master branch as well as the PR:
Congratulations: Merging this PR would fix the following tests:
All tests passing on the master branch were passed completely. Check the result page for more info. |
Collaborator
CCExtractor CI platform finished running the test files on windows. Below is a summary of the test results, when compared to test for commit 1510396...:
Congratulations: Merging this PR would fix the following tests:
All tests passing on the master branch were passed completely. Check the result page for more info. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
All OOM conditions now use
fatal(EXIT_NOT_ENOUGH_MEMORY, ...)following the project's coding patterns.Test plan
🤖 Generated with Claude Code