Skip to content

Add a TarReader fuzzer - #136660

Open
earbona23 wants to merge 1 commit into
dotnet:mainfrom
earbona23:tar-reader-fuzzer
Open

earbona23 wants to merge 1 commit into
dotnet:mainfrom
earbona23:tar-reader-fuzzer

Conversation

@earbona23

Copy link
Copy Markdown
Contributor

Adds a TarReader fuzzer to DotnetFuzzing, which currently has no coverage for System.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

InvalidDataException and EndOfStreamException only, because those are what TarReader documents for malformed and truncated archives (EndOfStreamException derives from the documented IOException).

I calibrated that choice rather than guessing: over 7000 mutated inputs (random bytes, bit flips over a valid archive, and truncations at every length) TarReader produced 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:

  • OverflowException from TarHelpers.ParseNumeric<T> on the GNU base-256 representation;
  • ArgumentOutOfRangeException from TarHeader.ProcessDataBlock when the size field 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.dict covers the ustar and GNU magics, the @LongLink/PaxHeader markers, all type flags, the pax keywords and the octal/base-256 numeric encodings.

Notes

No csproj change is needed: Fuzzers\*.cs and Dictionaries\* are already globbed, and Program.cs discovers fuzzers by reflection. System.Formats.Tar ships in the shared framework, so no ProjectReference is required either.

I did not declare a Corpus, since the corpora live in the Microsoft.DotNetFuzzing.TestData package. Happy to contribute a seed corpus there if you want one.

Fixes #136371.

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.
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Oct 29, 2026
@azure-pipelines

Copy link
Copy Markdown
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.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-meta
See info in area-owners.md if you want to be subscribed.

@earbona23

Copy link
Copy Markdown
Contributor Author

@dotnet-policy-service agree

@earbona23

Copy link
Copy Markdown
Contributor Author

A note on the red checks: they are infrastructure, not the fuzzer.

From the timeline of build 20261029.103, the records that actually failed are:

  • Monitor Helix Jobs, three times: "At timeout, 1 non-monitor Azure DevOps pipeline job(s) were still in progress or queued", followed by "Helix job monitor failed (exit code '1')"
  • osx-arm64 checked Libraries_CheckedCoreCLR: "We stopped hearing from agent Azure Pipelines 72"

For completeness, the Roslyn compiler cache steps logged error-type issues in the same build, three with exit code 1 and one post-job step with exit code 57005, but those records completed as succeededWithIssues and did not fail the build, so I am not counting them as the cause.

None of the failures comes from the added fuzzer, and no test or build error is attributed to the changed files.

I cannot trigger /azp run myself. Say the word and I will rebase onto current main to get a fresh run.

@earbona23

Copy link
Copy Markdown
Contributor Author

One more thing that may be getting in the way of this being looked at: the area label.

This PR landed on area-Meta, so the policy bot notified @dotnet/area-meta. The work it implements is #136371, "[System.Formats.Tar] Consider adding fuzzing for TarReader", which is labelled area-System.Formats.Tar and is still open and unassigned. The people who own the area the fuzzer actually targets have therefore never been notified about it.

Would area-System.Formats.Tar be the right label here, or does the fuzzing harness itself belong to a different area? I do not want to relabel anything myself, I just do not know which of the two owns a new fuzzer, and I would rather ask than guess.

Happy to split it, rebase it, or change the shape of the fuzzer if whoever owns it wants something different.

@earbona23

Copy link
Copy Markdown
Contributor Author

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 src/libraries/Fuzzing/DotnetFuzzing/Fuzzers/, by walking the add commit of each of the 20 fuzzers currently in that folder and by title search. I could pin the adding PR for eleven of the twenty, so this is a sample and not the whole population. The area label breaks down like this:

area label PRs that added a fuzzer
the target library's area #107385 (area-System.Formats.Nrbf), #114421 (area-System.IO.Compression), #111433 and #132201 (area-System.Net), #126352 and #133606 (area-System.Net.Security), #108247 (area-System.Runtime), #106509 (area-System.Buffers), #107195 (area-System.Reflection.Metadata), #103968 (area-System.Text.Encoding)
area-Meta #131306

Ten to one, and the one exception differs in a way that is visible in its diff: #131306 also changed eng/pipelines/libraries/fuzzing/deploy-to-onefuzz.yml, so it carried a genuine infrastructure change alongside the fuzzer. This PR changes two files, Fuzzers/TarReaderFuzzer.cs and Dictionaries/tar.dict, and no pipeline, project or harness file.

The other area-Meta PRs I found in this folder are consistent with the same split: #123597, #123079, #121950, #108555, #101993, #110761 and #108030 are the fuzzing infrastructure itself, coverage scripts, corpora, the shared-framework build and Program.cs. One more, #123170, is area-Meta and touches only Fuzzers/Deflate64Fuzzer.cs, so it cuts against me a little, though it is a fix to a fuzzer that already existed rather than the addition of a new one. docs/area-owners.md describes area-Meta as "Cross-cutting concerns that span many or all areas", which fits those and does not fit a fuzzer aimed at one type.

So the answer looks like area-System.Formats.Tar, by precedent rather than by my preference.

@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 area-System.Formats.Tar, open and unassigned. I am not asking for a review in the same breath: just for the PR to be visible to the people who own what it fuzzes.

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, Monitor Helix Jobs timing out and an osx-arm64 agent going away, neither of them from the fuzzer. I would rather not force-push a reviewed branch just to re-roll CI, but say the word and I will.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-formats-tar
See info in area-owners.md if you want to be subscribed.

@rzikm
rzikm requested a review from MihaZupan November 12, 2026 12:59
@iremyux iremyux self-assigned this Nov 12, 2026
@rzikm
rzikm requested a review from iremyux November 12, 2026 13:21
@iremyux iremyux removed their assignment Nov 12, 2026
}
}
}
catch (InvalidDataException)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we also catch NotSupportedException ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And InvalidOperationException ? Looks like GetNextEntry throws them

@@ -0,0 +1,40 @@
# tar archive format
magic_ustar="ustar\x00""00"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the "" correct here?

Comment on lines +29 to +40
byte[] buffer = ArrayPool<byte>.Shared.Rent(bytes.Length);
try
{
bytes.CopyTo(buffer);
return buffer;
}
catch
{
ArrayPool<byte>.Shared.Return(buffer);
throw;
}
}

@MihaZupan MihaZupan Nov 18, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there anything we can check about these values to see if they make sense instead of only that they don't throw?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.Formats.Tar community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[System.Formats.Tar] Consider adding fuzzing for TarReader

4 participants