{"record":{"id":"46c80c2cddf9112a","repo":"MuntashirAkon/AppManager","slug":"fieldname-name-is-too-long-namelen-bytes","errorCode":null,"errorMessage":"${fieldName} '${name}' is too long ( > ${NAMELEN} bytes)","messagePattern":"(.+?) '(.+?)' is too long \\( > (.+?) bytes\\)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java","lineNumber":686,"sourceCode":"        if (len >= TarConstants.NAMELEN) {\n\n            if (longFileMode == LONGFILE_POSIX) {\n                paxHeaders.put(paxHeaderName, name);\n                return true;\n            } else if (longFileMode == LONGFILE_GNU) {\n                // create a TarEntry for the LongLink, the contents\n                // of which are the link's name\n                final TarArchiveEntry longLinkEntry = new TarArchiveEntry(TarConstants.GNU_LONGLINK,\n                    linkType);\n\n                longLinkEntry.setSize(len + 1L); // +1 for NUL\n                transferModTime(entry, longLinkEntry);\n                putArchiveEntry(longLinkEntry);\n                write(encodedName.array(), encodedName.arrayOffset(), len);\n                write(0); // NUL terminator\n                closeArchiveEntry();\n            } else if (longFileMode != LONGFILE_TRUNCATE) {\n                throw new IllegalArgumentException(fieldName + \" '\" + name //NOSONAR\n                    + \"' is too long ( > \"\n                    + TarConstants.NAMELEN + \" bytes)\");\n            }\n        }\n        return false;\n    }\n\n    private void transferModTime(final TarArchiveEntry from, final TarArchiveEntry to) {\n        Date fromModTime = from.getModTime();\n        final long fromModTimeSeconds = fromModTime.getTime() / 1000;\n        if (fromModTimeSeconds < 0 || fromModTimeSeconds > TarConstants.MAXSIZE) {\n            fromModTime = new Date(0);\n        }\n        to.setModTime(fromModTime);\n    }\n}","sourceCodeStart":668,"sourceCodeEnd":702,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java#L668-L702","documentation":"TarArchiveOutputStream throws this IllegalArgumentException from handleLongName when an entry's path or link name exceeds the tar format limit of TarConstants.NAMELEN (100) bytes and the long-file-mode is not set to GNU/PAX/ERROR mode. The classic tar header stores names in a fixed 100-byte field, so the writer refuses to silently truncate. It is thrown during putArchiveEntry when encoding the entry name.","triggerScenarios":"Calling putArchiveEntry() on a TarArchiveOutputStream with an entry whose getName() is longer than 100 bytes while longFileMode is LONGFILE_ERROR (the default); same for a link name on a symlink entry.","commonSituations":"Archiving files with very long paths (e.g. deep node_modules trees, machine-generated filenames); copying entries from other archive formats without name limits; not configuring GNU or PAX long-name support before writing.","solutions":["Call tarArchiveOutputStream.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX) (or LONGFILE_GNU) before adding entries so long names are encoded in PAX/GNU extension headers","Shorten the entry name via entry.setName(relativePath) or by archiving relative to a base directory instead of absolute paths","If truncation is acceptable, setLongFileMode(LONGFILE_TRUNCATE) (the name will be cut at 100 bytes, likely unusable for extraction)","Pre-validate entry names in application code and reject/log paths > 100 bytes before writing"],"exampleFix":"// before\nTarArchiveOutputStream out = new TarArchiveOutputStream(fileOut);\nout.putArchiveEntry(new TarArchiveEntry(file, file.getAbsolutePath())); // absolute path > 100 bytes\n// after\nTarArchiveOutputStream out = new TarArchiveOutputStream(fileOut);\nout.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);\nout.putArchiveEntry(new TarArchiveEntry(file, relativize(file)));","handlingStrategy":"validation","validationCode":"private static void validateName(TarArchiveEntry entry) {\n    if (entry.getName().getBytes(StandardCharsets.UTF_8).length > TarConstants.NAMELEN) {\n        throw new IllegalArgumentException(\"Entry name exceeds 100 tar bytes: \" + entry.getName());\n    }\n}","typeGuard":"static boolean fitsInUstarHeader(TarArchiveEntry e) {\n    return e.getName().getBytes(StandardCharsets.UTF_8).length <= 100;\n}","tryCatchPattern":"try {\n    out.putArchiveEntry(entry);\n    // ... write contents\n    out.closeArchiveEntry();\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"is too long\")) {\n        out.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);\n        out.putArchiveEntry(entry); // retry with PAX long-name support\n    } else { throw e; }\n}","preventionTips":["Always call setLongFileMode(LONGFILE_POSIX) or LONGFILE_GNU when writing user-supplied paths","Archive relative paths, not absolute paths — strip the base directory prefix","Pre-scan the file list for names longer than 100 bytes before starting the archive","When copying entries from other archives, rewrite names that exceed the limit"],"tags":["java","tar","archive","file-name-length"],"backgroundTag":"invalid-argument-value","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}