diff options
author | Paulo Casanova <pasc@google.com> | 2017-03-21 23:33:52 +0000 |
---|---|---|
committer | Paulo Casanova <pasc@google.com> | 2017-03-22 00:21:36 +0000 |
commit | 7e52226688e009157cd4a1eb610e4bd6688a7690 (patch) | |
tree | 0e733163dc9d50103b0ba7f852cfc070203b7895 /src/main/java/com | |
parent | 766580e5455ebae4334b2120d40394e8b3f360e2 (diff) | |
download | apkzlib-7e52226688e009157cd4a1eb610e4bd6688a7690.tar.gz |
Fix bug 35841603: updating zip with invalid extra
ZFile did not support updating a zip that required aligning
an entry using the extra field if the previous entry had an
extra field that was non-empty but did not match the
format in the spec. With this update, the contents of the
extra field are discarded if they cannot be parsed.
http://b/35841603
Test: Included JUnit.
Change-Id: I977269b0648cd1b3fb7629929e02b9a00f2f0bbf
Diffstat (limited to 'src/main/java/com')
-rw-r--r-- | src/main/java/com/android/apkzlib/zip/ZFile.java | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/main/java/com/android/apkzlib/zip/ZFile.java b/src/main/java/com/android/apkzlib/zip/ZFile.java index bf16b59..c92e99b 100644 --- a/src/main/java/com/android/apkzlib/zip/ZFile.java +++ b/src/main/java/com/android/apkzlib/zip/ZFile.java @@ -934,9 +934,19 @@ public class ZFile implements Closeable { * the alignment field, if it exists. Also, sum the size of all kept extra field * segments. */ + ImmutableList<ExtraField.Segment> currentSegments; + try { + currentSegments = storedEntry.getLocalExtra().getSegments(); + } catch (IOException e) { + /* + * Parsing current segments has failed. This means the contents of the extra + * field are not valid. We'll continue discarding the existing segments. + */ + currentSegments = ImmutableList.of(); + } + List<ExtraField.Segment> extraFieldSegments = new ArrayList<>(); - int newExtraFieldSize = - storedEntry.getLocalExtra().getSegments().stream() + int newExtraFieldSize = currentSegments.stream() .filter(s -> s.getHeaderId() != ExtraField.ALIGNMENT_ZIP_EXTRA_DATA_FIELD_HEADER_ID) .peek(extraFieldSegments::add) |