summaryrefslogtreecommitdiff
path: root/src/main/java/com/android
diff options
context:
space:
mode:
authorPaulo Casanova <pasc@google.com>2017-10-27 13:43:14 +0100
committerPaulo Casanova <pasc@google.com>2017-10-27 22:17:22 +0000
commitf84d3f32271381f1103fb21142cdea30457251a6 (patch)
treed5540a3e9aee19e4f2020cfa58e3e4d4c9f6833a /src/main/java/com/android
parente27866a4f576fbf56e8faea6205d3e7ef615e21d (diff)
downloadapkzlib-f84d3f32271381f1103fb21142cdea30457251a6.tar.gz
Improved 4-byte alignment fixes.
This improves tests for 4-byte alignment and does some small code cleanup to make the reason why we need 6 bytes of header for 4 byte alignment more clear. Bug: http://b/67995001 Test: Included Change-Id: I12148519bb360c3b71e97d880f31f111c4feb4aa
Diffstat (limited to 'src/main/java/com/android')
-rw-r--r--src/main/java/com/android/apkzlib/zip/ExtraField.java9
-rw-r--r--src/main/java/com/android/apkzlib/zip/ZFile.java6
2 files changed, 11 insertions, 4 deletions
diff --git a/src/main/java/com/android/apkzlib/zip/ExtraField.java b/src/main/java/com/android/apkzlib/zip/ExtraField.java
index 4e11519..90c6fae 100644
--- a/src/main/java/com/android/apkzlib/zip/ExtraField.java
+++ b/src/main/java/com/android/apkzlib/zip/ExtraField.java
@@ -324,6 +324,11 @@ public class ExtraField {
public static class AlignmentSegment implements Segment {
/**
+ * Minimum size for an alignment segment.
+ */
+ public static final int MINIMUM_SIZE = 6;
+
+ /**
* The alignment value.
*/
private int alignment;
@@ -341,14 +346,14 @@ public class ExtraField {
*/
public AlignmentSegment(int alignment, int totalSize) {
Preconditions.checkArgument(alignment > 0, "alignment <= 0");
- Preconditions.checkArgument(totalSize >= 6, "totalSize < 6");
+ Preconditions.checkArgument(totalSize >= MINIMUM_SIZE, "totalSize < MINIMUM_SIZE");
/*
* We have 6 bytes of fixed data: header ID (2 bytes), data size (2 bytes), alignment
* value (2 bytes).
*/
this.alignment = alignment;
- padding = totalSize - 6;
+ padding = totalSize - MINIMUM_SIZE;
}
/**
diff --git a/src/main/java/com/android/apkzlib/zip/ZFile.java b/src/main/java/com/android/apkzlib/zip/ZFile.java
index 1e22d9b..6eb2691 100644
--- a/src/main/java/com/android/apkzlib/zip/ZFile.java
+++ b/src/main/java/com/android/apkzlib/zip/ZFile.java
@@ -232,9 +232,11 @@ public class ZFile implements Closeable {
private static final int MAXIMUM_EXTENSION_CYCLE_COUNT = 10;
/**
- * Minimum size for the extra field.
+ * Minimum size for the extra field when we have to add one. We rely on the alignment segment
+ * to do that so the minimum size for the extra field is the minimum size of an alignment
+ * segment.
*/
- private static final int MINIMUM_EXTRA_FIELD_SIZE = 6;
+ private static final int MINIMUM_EXTRA_FIELD_SIZE = ExtraField.AlignmentSegment.MINIMUM_SIZE;
/**
* Maximum size of the extra field.