Skip to content

fix(sourceanalysis): reject malformed ar member sizes instead of panicking - #3214

Merged
G-Rath merged 2 commits into
google:mainfrom
JayOfTheKeyboard:fix-ar-negative-size
Nov 4, 2026
Merged

G-Rath merged 2 commits into
google:mainfrom
JayOfTheKeyboard:fix-ar-negative-size

Conversation

@JayOfTheKeyboard

Copy link
Copy Markdown
Contributor

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=rust scan.

Fixes #3202

Details

readHeader in internal/thirdparty/ar/reader.go parsed the size field with strconv.Atoi and dropped the error. A non-numeric size became 0, and a negative size went through to Reader.Read, which sliced b[0:-n] and panicked.

This change:

  • parses the size in readHeader and returns an error if Atoi fails or the value is below zero;
  • removes byteToDecimal, which had no other callers.

The caller needs no change. rustAnalysis already logs failed to analyse '<path>' and skips the file when extractRlibArchive returns 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

  • Added Test_extractRlibArchive_malformedHeader in internal/sourceanalysis/rust_test.go, with a negative and a non-numeric size case. On main the negative case panics and the non-numeric case returns no error. Both pass with the fix.
  • Ran the CLI repro from Rust call analysis panics on an .rlib whose ar member header has a negative size, killing the scan #3202 against a build of this branch. It logs 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 on main at 0cf67b4.
  • ./scripts/run_lints.sh: 0 issues.

(Prepared with the help of an AI coding assistant.)

Checklist

another-rex
another-rex previously approved these changes Nov 3, 2026
@another-rex
another-rex enabled auto-merge (squash) November 3, 2026 22:19
Comment thread internal/sourceanalysis/rust_test.go Resolved
G-Rath
G-Rath previously approved these changes Nov 3, 2026
Comment thread internal/thirdparty/ar/reader.go Resolved
@codecov-commenter

codecov-commenter commented Nov 3, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.39%. Comparing base (e6b2b24) to head (c29ebb0).
⚠️ Report is 1 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

auto-merge was automatically disabled November 3, 2026 23:31

Head branch was pushed to by a user without write access

@JayOfTheKeyboard
JayOfTheKeyboard dismissed stale reviews from G-Rath and another-rex via 9445710 November 3, 2026 23:31
@G-Rath
G-Rath enabled auto-merge (squash) November 3, 2026 23:32
@JayOfTheKeyboard

Copy link
Copy Markdown
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
G-Rath force-pushed the fix-ar-negative-size branch from 9445710 to c29ebb0 Compare November 3, 2026 23:48
auto-merge was automatically disabled November 3, 2026 23:48

Head branch was pushed to by a user without write access

@G-Rath
G-Rath enabled auto-merge (squash) November 3, 2026 23:48
@G-Rath
G-Rath merged commit a336f37 into google:main Nov 4, 2026
33 of 38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rust call analysis panics on an .rlib whose ar member header has a negative size, killing the scan

4 participants