DEV Community

andreagomez
andreagomez

Posted on

A negative archive size should be rejected before an AR reader panics

A negative archive size should be rejected before an AR reader panics

The Go package github.com/blakesmith/ar has a denial-of-service flaw in its archive reader. GitHub advisory GHSA-8r27-mm5g-38ww describes a negative archive-member size that is parsed and accepted. The affected range includes the latest tagged pseudo-version listed by the advisory, and no patched version is listed. The severity is high, with an availability-only CVSS v3 vector of 7.5.

The parser trusts a numeric field

AR member headers contain a ten-byte decimal size field. Reader.Next parses that field with strconv.ParseInt but does not reject a negative value. The reader then carries a negative remaining byte count. A later call to Reader.Read uses that count in a slice expression and panics with a slice-bounds error.

The flaw is simple, but its location matters. Archive parsers often sit behind file uploads, package inspection, build tools, and malware-analysis services. A user or service may accept an archive from an untrusted source and assume the library will return an error for a malformed header. A panic can terminate the worker or make the service unavailable.

Treat archives as untrusted input

Validate member sizes before allocating buffers or calculating offsets. Reject negative values, overflow, and sizes that exceed the remaining input. Wrap parser calls in a process boundary where feasible so a panic cannot take down the main service. Recover from panics only as a last containment measure; recovery does not make a malformed archive safe to process.

Search SBOMs, module graphs, vendor bundles, and container images for github.com/blakesmith/ar. Because no patched version is listed, use a maintained fork, vendor patch, or remove the dependency where possible. Pin the replacement and add a regression test with a crafted negative size field. Fuzz the reader with malformed headers, empty names, and truncated payloads.

Investigation and service design

If a service parses untrusted AR files, isolate the parser in a worker with time, memory, and restart limits. Record the input hash and parser version before processing. A crash should produce a controlled failure and a telemetry event rather than a restart loop that hides the cause. Limit file size before the parser runs and reject archive formats that the product does not need.

Review logs for repeated panics or worker restarts after archive uploads. Check whether the service accepted the file before the crash and whether another component consumed it. If the archive is part of a build, rebuild from a trusted artifact and inspect the build cache.

The inventory question

An upstream package can be embedded in tools that never expose a web page. A public scan will not solve that inventory. The useful evidence is a dependency graph, a binary or container SBOM, and a list of services that accept AR files.

The absence of a fixed release makes the boundary controls more important. The safest immediate step is to stop feeding the vulnerable reader untrusted archives until a maintained replacement or patch is verified.

References

Top comments (0)