From d9b8f06adac48d40d7201d15d2396d193bc0e5e6 Mon Sep 17 00:00:00 2001 From: Raphael Date: Wed, 30 Nov 2011 22:51:08 -0800 Subject: SDK Manager: verbose print if unzip fails. The core issue was that source packages were not properly zipped on the build server side, which made the unzip crash with an EOFException. This simply adds a better verbose message in case this happens again. It seems the Java ZipFile bug listed in there is fixed at least in the JVM I'm currently running (1.6 and 7) but anyway I added the extra safeguard code as documented in the reported bug (e.g. don't ask ZipFile to unzip more than the actual size of the entry.) Can't hurt to have it. Change-Id: Ib47530920474e320da69c35d9a695d931bed55c1 --- .../sdklib/internal/repository/ArchiveInstaller.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'sdkmanager') diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/ArchiveInstaller.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/ArchiveInstaller.java index ee442e1..934044f 100755 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/ArchiveInstaller.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/ArchiveInstaller.java @@ -27,6 +27,7 @@ import com.android.sdklib.repository.RepoConstants; import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; import org.apache.commons.compress.archivers.zip.ZipFile; +import java.io.EOFException; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -703,15 +704,26 @@ public class ArchiveInstaller { } FileOutputStream fos = null; + long remains = entry.getSize(); try { fos = new FileOutputStream(destFile); - int n; + + // Java bug 4040920: do not rely on the input stream EOF and don't + // try to read more than the entry's size. InputStream entryContent = zipFile.getInputStream(entry); - while ((n = entryContent.read(buf)) != -1) { + int n; + while (remains > 0 && + (n = entryContent.read( + buf, 0, (int) Math.min(remains, buf.length))) != -1) { + remains -= n; if (n > 0) { fos.write(buf, 0, n); } } + } catch (EOFException e) { + monitor.logError("Error uncompressing file %s. Size: %d bytes, Unwritten: %d bytes.", + entry.getName(), entry.getSize(), remains); + throw e; } finally { if (fos != null) { fos.close(); -- cgit v1.1