Status Update
Comments
fl...@obfusk.net <fl...@obfusk.net> #2
If the existing file has 4k page alignment, --alignment-preserved
will still turn that into 16k unless --lib-page-alignment
is set to 4k. That doesn't seem correct to me.
fl...@obfusk.net <fl...@obfusk.net> #3
Actually, I was mistaken about the latter. It should indeed preserve existing (non)alignment with --alignment-preserved
. It just doesn't make sense for it to forcibly replace all padding -- even when alignment is already correct -- otherwise.
fl...@obfusk.net <fl...@obfusk.net> #4
From the apsigner
code (src/main/java/com/android/apksig/ApkSigner.java
):
if (inputOffset == outputOffset && mAlignmentPreserved) {
// This record's data will be aligned same as in the input APK.
return new OutputSizeAndDataOffset(
inputRecord.outputRecord(inputLfhSection, outputLfhSection),
inputRecord.getDataStartOffsetInRecord());
}
int dataAlignmentMultiple = getInputJarEntryDataAlignmentMultiple(inputRecord);
if ((dataAlignmentMultiple <= 1)
|| ((inputOffset % dataAlignmentMultiple) == (outputOffset % dataAlignmentMultiple)
&& mAlignmentPreserved)) {
// This record's data will be aligned same as in the input APK.
return new OutputSizeAndDataOffset(
inputRecord.outputRecord(inputLfhSection, outputLfhSection),
inputRecord.getDataStartOffsetInRecord());
}
long inputDataStartOffset = inputOffset + inputRecord.getDataStartOffsetInRecord();
if ((inputDataStartOffset % dataAlignmentMultiple) != 0 && mAlignmentPreserved) {
// This record's data is not aligned in the input APK. No need to align it in the
// output.
return new OutputSizeAndDataOffset(
inputRecord.outputRecord(inputLfhSection, outputLfhSection),
inputRecord.getDataStartOffsetInRecord());
}
The && mAlignmentPreserved
condition was added to all 3 if statements in 35.0.0-rc1. It seems to me that this is incorrect for the second one: if the record is already aligned correctly in the input APK and will continue to be aligned correctly in the output APK its padding should not be modified regardless of the value of mAlignmentPreserved
, which should only affect the first and third cases which are about preserving non-alignment for records whose offset will not change or that are not aligned in the input APK.
fl...@obfusk.net <fl...@obfusk.net> #5
Thus the && mAlignmentPreserved
check in the second if statement should be replaced with && (mAlignmentPreserved || (inputDataStartOffset % dataAlignmentMultiple) == 0)
.
jg...@google.com <jg...@google.com>
fl...@obfusk.net <fl...@obfusk.net> #6
Semi-related: --lib-page-alignment 65536
doesn't work (as 65536 doesn't fit in the short used to store the alignment in the extra field); so, unlike AGP and zipalign
, apksigner
doesn't support 64K page alignment (except by aligning the APK to 64K beforehand with AGP or zipalign
and using --alignment-preserved
).
fl...@obfusk.net <fl...@obfusk.net> #7
I'm not sure why apksigner
is the only tool that doesn't use/support zero padding (which AGP and zipalign
use), but maybe it should support that as well, at least optionally and for 64K alignment?
FWIW, zipalign.py
zipalign
versions from build-tools 31.0.0 and 32.0.0).
ba...@gmail.com <ba...@gmail.com> #8
(src/main/java/com/android/apksig/ApkSigner.java)
Description
apksigner
now forcibly replaces existing padding even when the file is already aligned as it should be, except when--alignment-preserved
is specified, in which case it will still align files that aren't already aligned correctly but keep existing padding for files that are.This means it will replace existing zero padding with different padding for each and every non-compressed file. This padding will not only be different but also longer for regular files aligned to 4 bytes with zero padding, but often the same size for
.so
shared objects aligned to 16k (unless they happened to require less than 6 bytes of zero padding before).This breaks coping the APK signature for Reproducible Builds using
apksigcopier
.See the for more details.
apksigcopier
FAQ entryI also fail to understand the logic here. Why replace existing padding if it's already correctly aligned? To me "alignment-preserved" seems to a misnomer. It will always ensure alignment. What it doesn't do is preserve the specific padding used for that alignment unless told to "preserve alignment".