From fc4f9921d55f55bf96c76effe4a2a406ef71fd40 Mon Sep 17 00:00:00 2001 From: Kushal Munir < kmunir@ca.ibm.com> Date: Wed, 20 Sep 2006 11:34:25 +0000 Subject: [PATCH] Bug 139207: Browsing into some remote tar archives via dstore fails, and crashes the dstore server. This only occurred for tars generated on Windows and the problem was with reading the last entries in the tar archive which are different when generated on Windows than on Linux. The tar format does not specify how archives should end, though it does recommend a certain format. The problem was fixed by making our code more robust when it comes to handling end of archive entries. --- .../clientserver/util/tar/TarFile.java | 35 ++++++++++++++++--- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/util/tar/TarFile.java b/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/util/tar/TarFile.java index d8a5e2f4910..e1d03802a9a 100644 --- a/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/util/tar/TarFile.java +++ b/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/util/tar/TarFile.java @@ -152,11 +152,24 @@ public class TarFile implements ITarConstants { // if header is not null, we add it to our list of headers if (header != null) { - // add header - blockHeaders.add(header); - // determine how many blocks make up the contents of the file - long fileSize = header.getSize(); + long fileSize = 0; + + // Bug 139207: Browsing into some tar archives failed + // The reason was that the last entry in the file did not necessarily have an empty string as the name + // of the entry and so the header is not null. The tar format does not guarantee an empty name. + // Instead we get a NumberFormatException when reading the size. We assume that the entries + // are not valid in such cases. + try { + fileSize = header.getSize(); + } + catch (NumberFormatException e) { + break; + } + + // add header only if the size is valid + blockHeaders.add(header); + int numFileBlocks = (int)(fileSize / BLOCK_SIZE); numFileBlocks += (fileSize % BLOCK_SIZE) > 0 ? 1 : 0; @@ -299,7 +312,19 @@ public class TarFile implements ITarConstants { // if header is not null, we add it to our list of headers if (header != null) { - long fileSize = header.getSize(); + long fileSize = 0; + + // Bug 139207: Browsing into some tar archives failed + // The reason was that the last entry in the file did not necessarily have an empty string as the name + // of the entry and so the header is not null. The tar format does not guarantee an empty name. + // Instead we get a NumberFormatException when reading the size. We assume that the entries + // are not valid in such cases. + try { + fileSize = header.getSize(); + } + catch (NumberFormatException e) { + break; + } // if the header name does not match the entry name if (!header.getName().equals(entry.getName())) {