From b6dc25a368ce68f557d31c854728ee4e2071c0cf Mon Sep 17 00:00:00 2001 From: Peter Gerber Date: Sat, 11 May 2019 12:00:58 +0200 Subject: [PATCH] Reproducible build: Ensure apkdiff.py works properly again MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The recent switch to Python3 (2ccdf0e396e82dd) introduced a regression that led to file content no longer being compared: In compareEntries(), two generators/iterators are created: sourceInfoList = filter(lambda sourceInfo: …, sourceZip.infolist()) destinationInfoList = filter(lambda destinationInfo: …, destinationZip.infolist()) Few lines later, those are exhausted: if len(sourceInfoList) != len(destinationInfoList): Yet another few lines later, the exhausted generator is used again: for sourceEntryInfo in sourceInfoList: … # <-- unreachable This is caused by behavioral differences between Python2 and Python3: user@z_signal:~$ python2 Python 2.7.13 (default, Sep 26 2018, 18:42:22) [GCC 6.3.0 20170516] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> f = filter(lambda i: i % 2 == 0, [0, 1, 2, 3, 4, 5, 6]) >>> list(f) [0, 2, 4, 6] >>> list(f) [0, 2, 4, 6] >>> user@z_signal:~$ python3 Python 3.5.3 (default, Sep 27 2018, 17:25:39) [GCC 6.3.0 20170516] on linux Type "help", "copyright", "credits" or "license" for more information. >>> f = filter(lambda i: i % 2 == 0, [0, 1, 2, 3, 4, 5, 6]) >>> list(f) [0, 2, 4, 6] >>> list(f) [] >>> --- apkdiff/apkdiff.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apkdiff/apkdiff.py b/apkdiff/apkdiff.py index ff1cc4981..da19bf59d 100755 --- a/apkdiff/apkdiff.py +++ b/apkdiff/apkdiff.py @@ -35,10 +35,10 @@ class ApkDiff: return True def compareEntries(self, sourceZip, destinationZip): - sourceInfoList = filter(lambda sourceInfo: sourceInfo.filename not in self.IGNORE_FILES, sourceZip.infolist()) - destinationInfoList = filter(lambda destinationInfo: destinationInfo.filename not in self.IGNORE_FILES, destinationZip.infolist()) + sourceInfoList = list(filter(lambda sourceInfo: sourceInfo.filename not in self.IGNORE_FILES, sourceZip.infolist())) + destinationInfoList = list(filter(lambda destinationInfo: destinationInfo.filename not in self.IGNORE_FILES, destinationZip.infolist())) - if len(list(sourceInfoList)) != len(list(destinationInfoList)): + if len(sourceInfoList) != len(destinationInfoList): print("APK info lists of different length!") return False @@ -61,7 +61,7 @@ class ApkDiff: sourceChunk = sourceFile.read(1024) destinationChunk = destinationFile.read(1024) - while sourceChunk != "" or destinationChunk != "": + while sourceChunk != b"" or destinationChunk != b"": if sourceChunk != destinationChunk: return False