diff --git a/WHATSNEW b/WHATSNEW index 3a65c2d38..1add234ec 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -84,6 +84,10 @@ Fixed bugs: extend Javadoc Bugzilla Report 56047 + * TarInputStream will now read archives created by tar + implementations that encode big numbers by not adding a trailing + NUL. + Other changes: -------------- diff --git a/src/main/org/apache/tools/tar/TarUtils.java b/src/main/org/apache/tools/tar/TarUtils.java index e88f6b40d..cc4106349 100644 --- a/src/main/org/apache/tools/tar/TarUtils.java +++ b/src/main/org/apache/tools/tar/TarUtils.java @@ -121,19 +121,18 @@ public class TarUtils { } } - // Must have trailing NUL or space - byte trailer; - trailer = buffer[end-1]; - if (trailer == 0 || trailer == ' '){ + // Trim all trailing NULs and spaces. + // The ustar and POSIX tar specs require a trailing NUL or + // space but some implementations use the extra digit for big + // sizes/uids/gids ... + byte trailer = buffer[end - 1]; + while (start < end && (trailer == 0 || trailer == ' ')) { end--; - } else { - throw new IllegalArgumentException( - exceptionMessage(buffer, offset, length, end-1, trailer)); + trailer = buffer[end - 1]; } - // May have additional NUL or space - trailer = buffer[end-1]; - if (trailer == 0 || trailer == ' '){ - end--; + if (start == end) { + throw new IllegalArgumentException( + exceptionMessage(buffer, offset, length, start, trailer)); } for ( ;start < end; start++) {