{"record":{"id":"28af1c39ebe833a8","repo":"MuntashirAkon/AppManager","slug":"error-detected-parsing-the-header","errorCode":null,"errorMessage":"Error detected parsing the header","messagePattern":"Error detected parsing the header","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java","lineNumber":368,"sourceCode":"            /* Skip will only go to the end of the current entry */\n            IOUtils.skip(this, Long.MAX_VALUE);\n\n            /* skip to the end of the last record */\n            skipRecordPadding();\n        }\n\n        final byte[] headerBuf = getRecord();\n\n        if (headerBuf == null) {\n            /* hit EOF */\n            currEntry = null;\n            return null;\n        }\n\n        try {\n            currEntry = new TarArchiveEntry(headerBuf, zipEncoding, lenient);\n        } catch (final IllegalArgumentException e) {\n            throw new IOException(\"Error detected parsing the header\", e);\n        }\n\n        entryOffset = 0;\n        entrySize = currEntry.getSize();\n\n        if (currEntry.isGNULongLinkEntry()) {\n            final byte[] longLinkData = getLongNameData();\n            if (longLinkData == null) {\n                // Bugzilla: 40334\n                // Malformed tar file - long link entry name not followed by\n                // entry\n                return null;\n            }\n            currEntry.setLinkName(zipEncoding.decode(longLinkData));\n        }\n\n        if (currEntry.isGNULongNameEntry()) {\n            final byte[] longNameData = getLongNameData();","sourceCodeStart":350,"sourceCodeEnd":386,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java#L350-L386","documentation":"Wraps an IllegalArgumentException raised while constructing a TarArchiveEntry from a raw header block in getNextTarEntry. The header bytes did not satisfy the entry constructor's invariants (e.g. unparseable numeric fields), so the stream converts it into an IOException signaling the archive is broken.","triggerScenarios":"getNextTarEntry() (via getNextEntry()) hits a header block whose name, mode, uid/gid, size, or mtime fields cannot be parsed — e.g. NUL-filled or random bytes where a valid octal field is expected.","commonSituations":"Reading a partially downloaded archive; parsing a file that is not a tar (e.g. a gzip file not wrapped in GZIPInputStream); archives written by non-compliant tools.","solutions":["Confirm the stream is a real tar file (check the 'ustar' magic bytes at offset 257 before parsing)","Wrap the stream in the correct decompressor (GZIPInputStream, XZInputStream...) if the archive is compressed","Re-download/re-extract the archive and verify its checksum","Catch IOException and abort with a user-facing 'corrupt archive' message"],"exampleFix":"// before\nTarArchiveInputStream in = new TarArchiveInputStream(new FileInputStream(f));\n// after\ntry (TarArchiveInputStream in = new TarArchiveInputStream(\n        new GZIPInputStream(new FileInputStream(f)))) {\n    // iterate entries\n} catch (IOException e) {\n    throw new IOException(\"Archive is corrupt or not a valid tar file\", e);\n}","handlingStrategy":"try-catch","validationCode":"byte[] magic = new byte[5];\ninput.mark(262); input.skip(257); input.readNBytes(magic, 0, 5); input.reset();\nif (!new String(magic, StandardCharsets.US_ASCII).equals(\"ustar\")) {\n    throw new IOException(\"not a tar file\");\n}","typeGuard":null,"tryCatchPattern":"try (TarArchiveInputStream in = new TarArchiveInputStream(stream)) {\n    TarArchiveEntry e;\n    while ((e = in.getNextTarEntry()) != null) { ... }\n} catch (IOException e) {\n    throw new IOException(\"Corrupt or non-tar archive\", e);\n}","preventionTips":["Check the ustar magic bytes before trusting a file as tar","Wrap compressed streams in the right decompressor first","Validate downloads against known hashes"],"tags":["tar","corrupt-archive","io"],"backgroundTag":"corrupt-archive-header","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}