Repository navigation
Conversation
cell_realloc() computes a 30% growth margin and stores the result in an int. For sizes of 1,651,910,422 bytes or greater, the floating-to-integer conversion is outside the representable range and has undefined behavior. toml_parse_file() can reach this while growing its input buffer. Compute the capacity exactly in int64_t and report allocation failure when it cannot be represented. Cover both sides of the boundary without allocating a multi-gigabyte buffer.
Owner
|
Thank you for this, @Marti2203 — the analysis was spot on. We ended up fixing it by a simpler route, so I'm closing this PR as fixed rather than merging it:
Why this route:
The limit is documented in |
cktan
added a commit
that referenced
this pull request
Oct 4, 2026
cell_realloc() grows a cell to size * 1.3 + 100. For a requested size of 1,651,910,422 bytes or more that exceeds INT_MAX, and converting it to int is undefined behavior. The file buffer in toml_parse_file_named() was the only cell that could get that big: tables and arrays are capped at 16k entries. Reject files of 1GB or larger with "file is too big" instead of the old INT_MAX - CHUNKSZ limit, which keeps the growth margin well within INT_MAX. Document the limit in the header and API.md. Reported by Martin Mirchev in #55. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
int64_tinttoml_parse_file()grows its input buffer throughcell_realloc(). At a requested size of 1,651,910,422 bytes,size * 1.3 + 100exceedsINT_MAX; converting that floating-point value tointhas undefined behavior.Validation
make -C test/pool clean testmake -C test/source testmake -C test/equiv testclang-format --dry-run --Werror src/tomlc17.c test/pool/test1.cgit diff --checkThe remaining project suites also passed through
merge; the aggregatemake testthen stopped instdtestbecause the externalgo/toml-testcommands are not installed in this environment.