@@ -303,31 +303,25 @@ public class TarInputStream extends FilterInputStream {
entryOffset = 0;
entrySize = currEntry.getSize();
if (currEntry.isGNULongNameEntry()) {
// read in the name
ByteArrayOutputStream longName = new ByteArrayOutputStream();
int length = 0;
while ((length = read(SMALL_BUF)) >= 0) {
longName.write(SMALL_BUF, 0, length);
}
getNextEntry();
if (currEntry == null) {
if (currEntry.isGNULongLinkEntry()) {
byte[] longLinkData = getLongNameData();
if (longLinkData == null) {
// Bugzilla: 40334
// Malformed tar file - long entry name not followed by entry
// Malformed tar file - long link entry name not followed by
// entry
return null;
}
byte[] longNameData = longName.toByteArray( );
// remove trailing null terminator(s)
length = longNameData.length;
while (length > 0 && longNameData[length - 1] == 0 ) {
--length ;
}
if (length != longNameData.length) {
byte[] l = new byte[length];
System.arraycopy(longNameData, 0, l, 0, length);
longNameData = l;
currEntry.setLinkName(encoding.decode(longLinkData));
}
if (currEntry.isGNULongNameEntry() ) {
byte[] longNameData = getLongNameData() ;
if (longNameData == null) {
// Bugzilla: 40334
// Malformed tar file - long entry name not followed by
// entry
return nul l;
}
currEntry.setName(encoding.decode(longNameData));
}
@@ -347,6 +341,39 @@ public class TarInputStream extends FilterInputStream {
return currEntry;
}
/**
* Get the next entry in this tar archive as longname data.
*
* @return The next entry in the archive as longname data, or null.
* @throws IOException on error
*/
protected byte[] getLongNameData() throws IOException {
// read in the name
ByteArrayOutputStream longName = new ByteArrayOutputStream();
int length = 0;
while ((length = read(SMALL_BUF)) >= 0) {
longName.write(SMALL_BUF, 0, length);
}
getNextEntry();
if (currEntry == null) {
// Bugzilla: 40334
// Malformed tar file - long entry name not followed by entry
return null;
}
byte[] longNameData = longName.toByteArray();
// remove trailing null terminator(s)
length = longNameData.length;
while (length > 0 && longNameData[length - 1] == 0) {
--length;
}
if (length != longNameData.length) {
byte[] l = new byte[length];
System.arraycopy(longNameData, 0, l, 0, length);
longNameData = l;
}
return longNameData;
}
/**
* Get the next record in this tar archive. This will skip
* over any remaining data in the current entry, if there