{"record":{"id":"eed008b4e5397d2e","repo":"pxb1988/dex2jar","slug":"error-reading-data-for-near-offset","errorCode":null,"errorMessage":"Error reading data for  near offset ","messagePattern":"Error reading data for  near offset ","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"dex-reader/src/main/java/com/googlecode/d2j/util/zip/ZipFile.java","lineNumber":295,"sourceCode":"        }\n    }\n\n    static class ZipInflaterInputStream extends InflaterInputStream {\n        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 {","sourceCodeStart":277,"sourceCodeEnd":313,"githubUrl":"https://github.com/pxb1988/dex2jar/blob/b5bda4fb4935ae8b3869b422454ae3b3896c7bc1/dex-reader/src/main/java/com/googlecode/d2j/util/zip/ZipFile.java#L277-L313","documentation":"Thrown by the ZipEntryInputStream.read() wrapper in dex-reader's bundled zip implementation. When the underlying inflater stream (super.read) throws an IOException while decompressing a zip entry, it is re-wrapped as 'Error reading data for <entryName> near offset <bytesRead>', preserving the entry name and bytes read so far plus the original cause.","triggerScenarios":"Calling ZipFile.getInputStream(entry).read(...) where the underlying stream read throws: corrupt or truncated deflate data, mismatched CRC/compression metadata, or an I/O fault reading the backing file mid-entry.","commonSituations":"Reading a corrupted, partially downloaded, or maliciously crafted .apk/.jar archive; archives modified after the central directory was written; disk/network faults while the archive is streamed.","solutions":["Verify archive integrity (zip -t / unzip -t) and re-obtain the file; the deflate stream is corrupt at that offset.","Inspect IOException.getCause() to distinguish zip format corruption from file I/O errors.","When processing untrusted archives, catch this IOException per entry and skip the bad entry instead of aborting the whole file.","Ensure the ZipFile's backing file is not truncated or closed while being read."],"exampleFix":"// before\ntry (InputStream in = zipFile.getInputStream(entry)) {\n    byte[] data = in.readAllBytes(); // throws on corrupt entry\n}\n// after\ntry (InputStream in = zipFile.getInputStream(entry)) {\n    byte[] data = in.readAllBytes();\n} catch (IOException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Error reading data for\")) {\n        logger.warn(\"Skipping corrupt zip entry\", e);\n    } else {\n        throw e;\n    }\n}","handlingStrategy":"try-catch","validationCode":"// Pre-check archive integrity before opening with ZipFile\nProcess p = new ProcessBuilder(\"unzip\", \"-t\", archivePath).redirectErrorStream(true).start();\nif (p.waitFor() != 0) throw new IllegalStateException(\"Archive corrupt: \" + archivePath);\n","typeGuard":"// Java has no type guards; validate entry metadata before reading\nstatic boolean isReadableEntry(ZipEntry e) {\n    return e != null && !e.isDirectory() && e.getSize() >= 0;\n}\n","tryCatchPattern":"try (InputStream in = zipFile.getInputStream(entry)) {\n    in.transferTo(out);\n} catch (IOException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Error reading data for\")) {\n        logger.warn(\"Corrupt zip entry skipped (offset info in message)\", e);\n    } else {\n        throw e;\n    }\n}\n","preventionTips":["Verify downloaded archives via checksum or unzip -t before parsing.","Catch IOException per entry so one bad entry does not abort whole-archive processing.","Inspect getCause() to distinguish format corruption from file I/O faults.","Never truncate or modify the archive while a ZipFile is open on it."],"tags":["zip","io","corrupt-archive","dex-reader"],"backgroundTag":"file-read-failed","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"}