Fixed extmap parsing and integer overflows#250
Open
sirzooro wants to merge 1 commit into
Open
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #250 +/- ##
==========================================
- Coverage 97.43% 97.41% -0.03%
==========================================
Files 12 12
Lines 1405 1390 -15
==========================================
- Hits 1369 1354 -15
Misses 19 19
Partials 17 17
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
This PR addresses several bugs in the SDP parser:
readUint64FieldandparseTimeUnits— values exceeding the type's range previously wrapped around silently; they now return asyntaxErrororerrSDPInvalidValue.ExtMapparsing logic — theerrcheck afterstrconv.ParseIntwas performed after the range check, which could mask parse errors; the order is now correct. Additionally, the upper bound of valid extmap keys was incorrectly246(the error message already said256); corrected to256.Changes
base_lexer.go— overflow-safereadUint64FieldReplaced the verbose per-digit
switch/casewith a compact digit-range check and an explicit overflow guard before each multiply-add step:Previously, values larger than
math.MaxUint64(e.g.2^64) would silently wrap around to 0. Now asyntaxErroris returned instead.base_lexer_test.go— uint64 overflow testAdded a test that verifies
readUint64Fieldreturns asyntaxErrorfor the value18446744073709551616(2^64), which previously wrapped to 0.extmap.go— two bug fixes inExtMap.UnmarshalOrder of checks: The range check on
valuewas performed before thestrconv.ParseInterror check, meaning a parse failure could silently fall through to the range check. The two checks are now in the correct order: parse error first, range check second.Correct upper bound: The upper bound was
246even though the error message stated1-256. Corrected to256.extmap_test.go— boundary value tests forExtMap.UnmarshalAdded a table-driven test covering all four boundary cases:
0→ rejected (below lower bound)1→ accepted (lower bound)256→ accepted (upper bound)257→ rejected (above upper bound)unmarshal.go— overflow-safeparseTimeUnitsAdded a pre-multiplication overflow guard when applying the time-unit multiplier
k(seconds/minutes/hours/days):Without this check, an input such as
9223372036854775807hwould overflowint64silently.unmarshal_test.go—parseTimeUnitsoverflow testsAdded
TestParseTimeUnits_Overflowcovering:h(hours) multiplierhmultiplierd(days) multiplier