Fix zipalign alignment error
Problem: Zipalign operates over several false assumptions. First it
assumes that zip entries are in the same order in the body and in
the Central Direcotry. Second, it assumes there are not space
between entries. This makes alignment incorrect when these asserts
are not true.
Solution: Don't align entries by tracking bias based on input zip
entry location. Calculate the expected alignment based on the out-
put zip file and correct with extra padding.
Fixes: 162117652
Test: Units Tests
Change-Id: Ia179338f658cab18a377cba2c7c8e629089a2785
diff --git a/tools/zipalign/ZipFile.h b/tools/zipalign/ZipFile.h
index 11d20c5..854f981 100644
--- a/tools/zipalign/ZipFile.h
+++ b/tools/zipalign/ZipFile.h
@@ -102,14 +102,14 @@
}
/*
- * Add an entry by copying it from another zip file. If "padding" is
- * nonzero, the specified number of bytes will be added to the "extra"
- * field in the header.
+ * Add an entry by copying it from another zip file. If "alignment" is
+ * nonzero, an appropriate number of bytes will be added to the "extra"
+ * field in the header so the entry payload is aligned.
*
* If "ppEntry" is non-NULL, a pointer to the new entry will be returned.
*/
status_t add(const ZipFile* pSourceZip, const ZipEntry* pSourceEntry,
- int padding, ZipEntry** ppEntry);
+ int alignment, ZipEntry** ppEntry);
/*
* Add an entry by copying it from another zip file, recompressing with
@@ -163,6 +163,8 @@
ZipFile(const ZipFile& src);
ZipFile& operator=(const ZipFile& src);
+ status_t alignEntry(android::ZipEntry* pEntry, uint32_t alignTo);
+
class EndOfCentralDir {
public:
EndOfCentralDir(void) :