{"record":{"id":"6a4c42b2e030aef2","repo":"pxb1988/dex2jar","slug":"size-mismatch-on-inflated-file-vs","errorCode":null,"errorMessage":"Size mismatch on inflated file:  vs ","messagePattern":"Size mismatch on inflated file:  vs ","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"dex-reader/src/main/java/com/googlecode/d2j/util/zip/ZipFile.java","lineNumber":299,"sourceCode":"        private final ZipEntry entry;\n        private long bytesRead = 0;\n\n        public ZipInflaterInputStream(InputStream is, Inflater inf, int bsize, ZipEntry entry) {\n            super(is, inf, bsize);\n            this.entry = entry;\n        }\n\n        @Override\n        public int read(byte[] buffer, int byteOffset, int byteCount) throws IOException {\n            final int i;\n            try {\n                i = super.read(buffer, byteOffset, byteCount);\n            } catch (IOException e) {\n                throw new IOException(\"Error reading data for \" + entry.getName() + \" near offset \" + bytesRead, e);\n            }\n            if (i == -1) {\n                if (entry.size != bytesRead) {\n                    throw new IOException(\"Size mismatch on inflated file: \" + bytesRead + \" vs \" + entry.size);\n                }\n            } else {\n                bytesRead += i;\n            }\n            return i;\n        }\n\n        @Override\n        public int available() throws IOException {\n            return super.available() == 0 ? 0 : (int) (entry.getSize() - bytesRead);\n        }\n    }\n\n    private static class ByteBufferBackedInputStream extends InputStream {\n        private final ByteBuffer buf;\n\n        public ByteBufferBackedInputStream(ByteBuffer buf) {\n            this.buf = buf;","sourceCodeStart":281,"sourceCodeEnd":317,"githubUrl":"https://github.com/pxb1988/dex2jar/blob/b5bda4fb4935ae8b3869b422454ae3b3896c7bc1/dex-reader/src/main/java/com/googlecode/d2j/util/zip/ZipFile.java#L281-L317","documentation":"Thrown by the same wrapped entry stream when the entry inflates without error but at EOF the total bytes read (bytesRead) does not equal the entry's declared uncompressed size (entry.size). The library enforces the size contract from the zip directory against actual inflated output.","triggerScenarios":"Reading an entry to EOF (read() returning -1) where inflated byte count != entry.size: entries written with wrong/placeholder size fields (streaming zip writers using data descriptors), manually patched archives, or non-standard repackaging tools.","commonSituations":"Archives built by streaming compressors that store 0/placeholder sizes in headers; apks/jars repackaged by non-compliant tools; truncated or appended-to archives.","solutions":["Rebuild the archive with a standards-compliant zip tool so entry sizes match the data.","Check whether entry.size was populated from a local header with placeholder sizes (streaming entries) and use the central directory value instead.","Catch this IOException and treat the entry as suspect; optionally consume via the raw inflater path if the data is known-good.","Compare central directory offsets against actual file length to detect truncation."],"exampleFix":"// before\ntry (InputStream in = zipFile.getInputStream(entry)) {\n    in.transferTo(out); // throws 'Size mismatch on inflated file'\n}\n// after\ntry {\n    try (InputStream in = zipFile.getInputStream(entry)) {\n        in.transferTo(out);\n    }\n} catch (IOException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Size mismatch on inflated file\")) {\n        logger.warn(\"Entry size field inconsistent; treating entry as suspect\", e);\n    } else {\n        throw e;\n    }\n}","handlingStrategy":"validation","validationCode":"// Compare declared entry size against actual inflated bytes after reading\nstatic boolean sizeConsistent(ZipEntry e, byte[] inflated) {\n    return e.getSize() < 0 || e.getSize() == inflated.length;\n}\n","typeGuard":"static boolean hasDeclaredSize(ZipEntry e) {\n    return e != null && e.getSize() >= 0; // -1 = size unknown (streaming/data-descriptor entry)\n}\n","tryCatchPattern":"try {\n    try (InputStream in = zipFile.getInputStream(entry)) {\n        in.transferTo(out);\n    }\n} catch (IOException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Size mismatch on inflated file\")) {\n        logger.warn(\"Declared size disagrees with inflated data; entry suspect: \" + e.getMessage());\n    } else {\n        throw e;\n    }\n}\n","preventionTips":["Prefer archives built with standards-compliant zip writers that fill size fields correctly.","Treat entries with size = -1 (data-descriptor/streaming entries) as suspect in this library.","Validate central directory offsets against actual file length to detect truncation.","Keep a known-good checksum for archives repackaged by other tools."],"tags":["zip","io","size-mismatch","dex-reader"],"backgroundTag":"checksum-mismatch","analyzedSha":"b5bda4fb4935ae8b3869b422454ae3b3896c7bc1","analyzedAt":"2026-09-08T00:44:01.258Z","contentChangedAt":"2026-09-08T00:44:01.258Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}