Index: Lib/zipfile.py =================================================================== --- Lib/zipfile.py (revision 87589) +++ Lib/zipfile.py (working copy) @@ -256,7 +256,14 @@ # Try to read the "Zip64 end of central directory" structure return _EndRecData64(fpin, maxCommentStart + start - filesize, endrec) - + else: + # be robust to non-comment extaneous data after endrec + # by making it a comment so that nothing is ever lost + endrec[_ECD_COMMENT_SIZE] = len(comment) + endrec.append(comment) + endrec.append(maxCommentStart + start) + return endrec + # Unable to find a valid end of central directory structure return Index: Lib/test/test_zipfile.py =================================================================== --- Lib/test/test_zipfile.py (revision 87589) +++ Lib/test/test_zipfile.py (working copy) @@ -348,6 +348,14 @@ f.seek(len(data)) with zipfile.ZipFile(f, "r") as zipfp: self.assertEqual(zipfp.namelist(), [TESTFN]) + + def test_ignores_newline_at_end(self): + with zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED) as zipfp: + zipfp.write(TESTFN, TESTFN) + with open(TESTFN2, 'a') as f: + f.write("\r\n") + with zipfile.ZipFile(TESTFN2, "r") as zipfp: + self.assertIsInstance(zipfp, zipfile.ZipFile) def test_write_default_name(self): """Check that calling ZipFile.write without arcname specified