]> Cypherpunks.ru repositories - gostls13.git/commit
archive/tar: detect out of bounds accesses in PAX records resulting from padded lengths
authorEmmanuel T Odeke <emmanuel@orijtech.com>
Thu, 4 Feb 2021 09:39:18 +0000 (01:39 -0800)
committerEmmanuel Odeke <emmanuel@orijtech.com>
Tue, 9 Feb 2021 05:28:50 +0000 (05:28 +0000)
commite0ac989cf3e43ec77c7205a66cb1cd63dd4d3043
tree41cf3eaab9fb6813f46141c9f5fb079d929b21b7
parentc9d6f45fec19a9cb66ddd89d61bfa982f5bf4afe
archive/tar: detect out of bounds accesses in PAX records resulting from padded lengths

Handles the case in which padding of a PAX record's length field
violates invariants about the formatting of record, whereby it no
longer matches the prescribed format:

    "%d %s=%s\n", <length>, <keyword>, <value>

as per:

    https://pubs.opengroup.org/onlinepubs/9699919799/utilities/pax.html#tag_20_92_13_03

0-padding, and paddings of other sorts weren't handled and we assumed
that only non-padded decimal lengths would be passed in.
Added test cases to ensure that the parsing still proceeds as expected.

The prior crashing repro:

    0000000000000000000000000000000030 mtime=1432668921.098285006\n30 ctime=2147483649.15163319

exposed the fallacy in the code, that assumed that the length would ALWAYS be a
non-padded decimal length string.

This bug has existed since Go1.1 as per CL 6700047.

Thanks to Josh Bleecher Snyder for fuzzing this package, and thanks to Tom
Thorogood for advocacy, raising parity with GNU Tar, but for providing more test cases.

Fixes #40196

Change-Id: I32e0af4887bc9221481bd9e8a5120a79f177f08c
Reviewed-on: https://go-review.googlesource.com/c/go/+/289629
Trust: Emmanuel Odeke <emmanuel@orijtech.com>
Trust: Joe Tsai <thebrokentoaster@gmail.com>
Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
src/archive/tar/strconv.go
src/archive/tar/strconv_test.go