Repository navigation
fix(sourceanalysis): reject malformed ar member sizes instead of panicking - #3214
Merged
Merged
Conversation
another-rex
previously approved these changes
Nov 3, 2026
another-rex
enabled auto-merge (squash)
November 3, 2026 22:19
G-Rath
reviewed
Nov 3, 2026
G-Rath
previously approved these changes
Nov 3, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3214 +/- ##
==========================================
+ Coverage 82.38% 82.39% +0.01%
==========================================
Files 120 120
Lines 7759 7761 +2
==========================================
+ Hits 6392 6395 +3
+ Misses 1367 1366 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
auto-merge was automatically disabled
November 3, 2026 23:31
Head branch was pushed to by a user without write access
JayOfTheKeyboard
dismissed stale reviews from G-Rath and another-rex
via
November 3, 2026 23:31
9445710
G-Rath
approved these changes
Nov 3, 2026
G-Rath
enabled auto-merge (squash)
November 3, 2026 23:32
Contributor
Author
|
Thanks, both done in 9445710. The error shows the raw size field, since a non-numeric one has no number to print. |
…cking readHeader parsed the member size with strconv.Atoi, dropped the error, and never checked the sign. A negative size made Reader.Read slice b[0:-n] and panic, which kills the whole scan under --call-analysis=rust. A non-numeric size silently became 0. Return an error for both so extractRlibArchive's caller logs it and skips the file, as it already does for other unreadable archives.
G-Rath
force-pushed
the
fix-ar-negative-size
branch
from
November 3, 2026 23:48
9445710 to
c29ebb0
Compare
auto-merge was automatically disabled
November 3, 2026 23:48
Head branch was pushed to by a user without write access
G-Rath
enabled auto-merge (squash)
November 3, 2026 23:48
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.
Overview
Return an error from the vendored ar reader when a member header has a negative or non-numeric size. Before this, a negative size panicked and ended the whole
--call-analysis=rustscan.Fixes #3202
Details
readHeaderininternal/thirdparty/ar/reader.goparsed the size field withstrconv.Atoiand dropped the error. A non-numeric size became 0, and a negative size went through toReader.Read, which slicedb[0:-n]and panicked.This change:
readHeaderand returns an error ifAtoifails or the value is below zero;byteToDecimal, which had no other callers.The caller needs no change.
rustAnalysisalready logsfailed to analyse '<path>'and skips the file whenextractRlibArchivereturns an error.A size field that is blank or left-padded with spaces used to read as 0 and is now rejected. rustc and GNU ar write it left-aligned, so this shouldn't affect real archives. The issue also mentioned checking the header's trailing magic. As this needs crafted input, I left that out to keep the change small.
Testing
Test_extractRlibArchive_malformedHeaderininternal/sourceanalysis/rust_test.go, with a negative and a non-numeric size case. Onmainthe negative case panics and the non-numeric case returns no error. Both pass with the fix.invalid size in ar header for "/0"and the scan still prints its results (the smallvec advisories).make test: one failure,TestCommand_LockfileWithExplicitParseAs/dpkg-status_is_supported, which fails the same way onmainat 0cf67b4../scripts/run_lints.sh: 0 issues.(Prepared with the help of an AI coding assistant.)
Checklist
./scripts/run_lints.sh../scripts/run_tests.sh.