feat: parser safety nets — multi-array validation + input-size cap - #3
Merged
Conversation
…input The variable_array_sane? check (added in PR #2) covered POLYGON/POLYLINE/ POLYBEZIER/POLYBEZIERTO/POLYLINETO + their 16-bit variants + POLYDRAW/16. This commit extends the check to multi-array records: - POLYPOLYGON, POLYPOLYLINE, POLYPOLYGON16, POLYPOLYLINE16: each has TWO variable arrays (aPolyCounts and aptl/apts). Both counts are now validated against nSize before bindata tries to allocate. Adds MAX_INPUT_BYTES = 200 MB guard at the parser entry point. Refuses inputs larger than 200 MB before any allocation. The 5.7 MB EMF fixture in the corpus is large; 200 MB is a generous safety margin.
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.
feat: parser safety nets — multi-array validation + input-size cap
The
variable_array_sane?check introduced in PR #2 covered thecommon single-array records (POLYGON, POLYLINE, POLYBEZIER, POLYDRAW,
etc.). This commit closes two remaining pathological-allocation
vectors.
What it does
Extends array sanity check to multi-array records.
POLYPOLYGON,POLYPOLYLINE,POLYPOLYGON16,POLYPOLYLINE16each carry TWO variable-length arrays:
aPolyCounts(
nPolysuint32s) andaptl/apts(cTotalentries). Previouslyonly the second array was validated; corrupt first-array counts
could still trigger massive allocations.
nSizebefore bindataattempts to allocate.
Adds a global input-size cap.
MAX_INPUT_BYTES = 200 MBenforced at the parser entry point.Emf::FormatErrorimmediately, before anyallocation.
Why it matters
The original
cpts=41026074hang in PR #2 came from a single-arrayrecord. The same class of bug exists for the multi-array records —
the parser is now safe against pathological inputs from any source
(corrupt fixtures, hostile callers, accidental
wc -coutputs).Verification
emf-corrupted/files still parse without crashing or hanging.parsing begins.