Repository navigation
Refactor allocation and image-size overflow checks with private C99 helpers - #289
Draft
sundaysebasidian-byte wants to merge 1 commit into
Draft
sundaysebasidian-byte wants to merge 1 commit into
sundaysebasidian-byte wants to merge 1 commit into
Conversation
Use private C99 checked size_t add and multiply helpers for allocation, buffer growth and image sizes. Preserve API errors and progressive overflow sentinels, with boundary and normal-image regression tests. Related to randy408#217. Implemented, tested and reviewed with OpenAI Codex AI assistance.
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.
Related to #217.
Changes
Add private C99 checked
size_tadd/multiply helpers and use them for allocation sizes, scanline/image sizes, and buffer growth. They return overflow without modifying the result and handle zero operands and aliased inputs. Public headers and ABI are unchanged; existing error codes and the progressive image-size overflow sentinel are preserved.This also replaces the ineffective encoded-buffer doubling guard and avoids division by zero in the zero-item allocation check. This is focused preventive hardening, not a claim of a discovered exploit or an exhaustive arithmetic audit. Remaining bounded serialization/counter calculations are outside this change.
Add a development-only regression executable covering zero/exact-limit/overflow cases, allocator rejection without giant allocations, growth/cache boundaries, image-size failures and progressive behavior. Normal-image coverage includes all 15 legal PNG color/depth combinations, six image sizes, both interlace modes and ordinary/progressive encoding and decoding (360 encodes, 720 decodes), including actual output-buffer growth.
Validation
On macOS ARM64 with Apple Clang 21, using the repository-pinned libpng 1.6.37 and miniz 2.2.0:
-Wall -Wextra -Werror -pedanticchecks on ARM64 and x86_64; x86_64 tests executed under Rosetta. i386 production/test compilation passed.The host's newer libpng 1.6.58 caused two pre-existing baseline metadata failures; the full-suite counts above use the project's pinned version. Actual 32-bit execution, Windows/MSVC, Linux/GCC, MemorySanitizer and a live OSS-Fuzz corpus campaign were not run. No performance benchmark was performed.
AI disclosure
Implementation, regression tests and review were produced with OpenAI Codex AI assistance, including separate AI review agents. The review was not performed by an independent human. The submitted files are exactly the locally tested and reviewed snapshot.