Skip to content

Commit b129b7c

Browse files
authored
Reject negative PAX size values when reading TAR headers (#128368)
This change adds a validation check while applying extended attributes in TarHeader.Read.cs so that a negative size value from PAX metadata now throws InvalidDataException instead of being accepted.
1 parent 3366f6a commit b129b7c

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarHeader.Read.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ internal void ReplaceNormalAttributesWithExtended(IEnumerable<KeyValuePair<strin
151151
// The 'size' header field only fits 12 bytes, so the data section length that surpases that limit needs to be retrieved
152152
if (TarHelpers.TryGetStringAsBaseTenLong(ExtendedAttributes, PaxEaSize, out long size))
153153
{
154+
if (size < 0)
155+
{
156+
throw new InvalidDataException(SR.Format(SR.TarSizeFieldNegative));
157+
}
158+
154159
_size = size;
155160
}
156161

0 commit comments

Comments
 (0)