Repository navigation
Add a TarReader fuzzer - #136660
Add a TarReader fuzzer#136660earbona23 wants to merge 1 commit into
Conversation
DotnetFuzzing has no coverage for System.Formats.Tar. This adds a fuzzer that reads the input as a tar archive through TarReader, synchronously and asynchronously, touching the parsed header fields and draining each entry's data stream so the numeric and string parsers are exercised. InvalidDataException and EndOfStreamException are swallowed because they are what TarReader documents for malformed and truncated archives. Calibrating against 7000 mutated inputs (random bytes, bit flips over a valid archive, truncations) produced only those two, so anything else escaping is a real finding. Running it surfaced two undocumented exceptions straight away, reported in dotnet#136659: an OverflowException out of TarHelpers.ParseNumeric for the GNU base-256 representation, and an ArgumentOutOfRangeException out of TarHeader.ProcessDataBlock for a size field that overflows. Also adds a tar dictionary covering the ustar and GNU magics, the type flags, the pax keywords and the numeric field encodings. Fixes dotnet#136371.
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
|
Tagging subscribers to this area: @dotnet/area-meta |
|
@dotnet-policy-service agree |
|
A note on the red checks: they are infrastructure, not the fuzzer. From the timeline of build
For completeness, the None of the failures comes from the added fuzzer, and no test or build error is attributed to the changed files. I cannot trigger |
|
One more thing that may be getting in the way of this being looked at: the area label. This PR landed on Would Happy to split it, rebase it, or change the shape of the fuzzer if whoever owns it wants something different. |
|
Answering my own label question above with measurement instead of leaving it open, since it is the one thing holding this PR in a room without the relevant owners in it. I looked at every PR I could identify that added a new file under
Ten to one, and the one exception differs in a way that is visible in its diff: #131306 also changed The other So the answer looks like @rzikm, you triaged #136659 two days ago, which is the same area and the same reader. Would you mind relabelling this one? It implements #136371, "[System.Formats.Tar] Consider adding fuzzing for TarReader", which is already Nothing has changed on my side since 1 November, and I have not rebased: the red checks are still the two infrastructure failures itemised above, |
|
Tagging subscribers to this area: @dotnet/area-system-formats-tar |
| } | ||
| } | ||
| } | ||
| catch (InvalidDataException) |
There was a problem hiding this comment.
Shouldn't we also catch NotSupportedException ?
There was a problem hiding this comment.
And InvalidOperationException ? Looks like GetNextEntry throws them
| @@ -0,0 +1,40 @@ | |||
| # tar archive format | |||
| magic_ustar="ustar\x00""00" | |||
| byte[] buffer = ArrayPool<byte>.Shared.Rent(bytes.Length); | ||
| try | ||
| { | ||
| bytes.CopyTo(buffer); | ||
| return buffer; | ||
| } | ||
| catch | ||
| { | ||
| ArrayPool<byte>.Shared.Return(buffer); | ||
| throw; | ||
| } | ||
| } |
There was a problem hiding this comment.
| byte[] buffer = ArrayPool<byte>.Shared.Rent(bytes.Length); | |
| try | |
| { | |
| bytes.CopyTo(buffer); | |
| return buffer; | |
| } | |
| catch | |
| { | |
| ArrayPool<byte>.Shared.Return(buffer); | |
| throw; | |
| } | |
| } | |
| byte[] buffer = ArrayPool<byte>.Shared.Rent(bytes.Length); | |
| bytes.CopyTo(buffer); | |
| return buffer; | |
| } |
| break; | ||
| } | ||
|
|
||
| // Access the parsed header fields to exercise the numeric and string parsers. |
There was a problem hiding this comment.
Is there anything we can check about these values to see if they make sense instead of only that they don't throw?
Adds a
TarReaderfuzzer to DotnetFuzzing, which currently has no coverage forSystem.Formats.Tar.The fuzzer reads the input as a tar archive, synchronously and asynchronously, touches the parsed header fields (
Name,EntryType,Format,Length,Mode,Uid,Gid,ModificationTime,LinkName) and drains each entry's data stream, so the numeric and string parsers and the data-block handling are all exercised.Which exceptions are swallowed
InvalidDataExceptionandEndOfStreamExceptiononly, because those are whatTarReaderdocuments for malformed and truncated archives (EndOfStreamExceptionderives from the documentedIOException).I calibrated that choice rather than guessing: over 7000 mutated inputs (random bytes, bit flips over a valid archive, and truncations at every length)
TarReaderproduced those two and nothing else. So anything else that escapes is a real finding, which keeps the signal clean for OneFuzz.It already found two things
Running it surfaced two undocumented exceptions within seconds, reported separately in #136659:
OverflowExceptionfromTarHelpers.ParseNumeric<T>on the GNU base-256 representation;ArgumentOutOfRangeExceptionfromTarHeader.ProcessDataBlockwhen thesizefield overflows.Both reproduce from a 1536-byte archive with a valid checksum. I deliberately did not add catches for them, so the fuzzer reports them as the findings they are. If you would rather merge the fuzzer before those are fixed, say so and I will add two temporary catches referencing #136659, or fold the fix into this PR, whichever you prefer.
Dictionary
tar.dictcovers the ustar and GNU magics, the@LongLink/PaxHeadermarkers, all type flags, the pax keywords and the octal/base-256 numeric encodings.Notes
No csproj change is needed:
Fuzzers\*.csandDictionaries\*are already globbed, andProgram.csdiscovers fuzzers by reflection.System.Formats.Tarships in the shared framework, so noProjectReferenceis required either.I did not declare a
Corpus, since the corpora live in theMicrosoft.DotNetFuzzing.TestDatapackage. Happy to contribute a seed corpus there if you want one.Fixes #136371.