Browse Source

another fix from commons - tar doesn't use specified encoding when reading GNU long names

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1429212 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 12 years ago
parent
commit
1fe6b17d5f
1 changed files with 14 additions and 7 deletions
  1. +14
    -7
      src/main/org/apache/tools/tar/TarInputStream.java

+ 14
- 7
src/main/org/apache/tools/tar/TarInputStream.java View File

@@ -302,11 +302,11 @@ public class TarInputStream extends FilterInputStream {

if (currEntry.isGNULongNameEntry()) {
// read in the name
StringBuffer longName = new StringBuffer();
ByteArrayOutputStream longName = new ByteArrayOutputStream();
byte[] buf = new byte[SMALL_BUFFER_SIZE];
int length = 0;
while ((length = read(buf)) >= 0) {
longName.append(new String(buf, 0, length)); // TODO default charset?
longName.write(buf, 0, length);
}
getNextEntry();
if (currEntry == null) {
@@ -314,12 +314,19 @@ public class TarInputStream extends FilterInputStream {
// Malformed tar file - long entry name not followed by entry
return null;
}
// remove trailing null terminator
if (longName.length() > 0
&& longName.charAt(longName.length() - 1) == 0) {
longName.deleteCharAt(longName.length() - 1);
byte[] longNameData = longName.toByteArray();
// remove trailing null terminator(s)
length = longNameData.length;
while (length > 0 && longNameData[length - 1] == 0) {
--length;
}
currEntry.setName(longName.toString());
if (length != longNameData.length) {
byte[] l = new byte[length];
System.arraycopy(longNameData, 0, l, 0, length);
longNameData = l;
}
currEntry.setName(encoding.decode(longNameData));
}

if (currEntry.isPaxHeader()){ // Process Pax headers


Loading…
Cancel
Save