{"record":{"id":"47dff8c9fbe34fdb","repo":"Tencent/tinker","slug":"property-too-long-in-utf-8-bytes-length-byte","errorCode":null,"errorMessage":"${property} too long in UTF-8:${bytes.length} bytes","messagePattern":"(.+?) too long in UTF-8:(.+?) bytes","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"third-party/tinker-ziputils/src/main/java/com/tencent/tinker/ziputils/ziputil/TinkerZipOutputStream.java","lineNumber":598,"sourceCode":"            throw new IOException(\"Zip entry size (\" + totalBytes +\n                    \" bytes) cannot be represented in the zip format (needs Zip64).\" +\n                    \" Set the entry length using ZipEntry#setLength to use Zip64 where necessary.\");\n        }*/\n        if (currentEntry.getMethod() == STORED) {\n            out.write(buffer, offset, byteCount);\n        } else {\n            out.write(buffer, offset, byteCount);\n        }\n        // crc.update(buffer, offset, byteCount);\n    }\n    private void checkOpen() throws IOException {\n        if (cDir == null) {\n            throw new IOException(\"Stream is closed\");\n        }\n    }\n    private void checkSizeIsWithinShort(String property, byte[] bytes) {\n        if (bytes.length > 0xffff) {\n            throw new IllegalArgumentException(property\n                + \" too long in UTF-8:\"\n                + bytes.length\n                + \" bytes\");\n        }\n    }\n    /*private long getBytesWritten() {\n        // This cast is somewhat messy but less error prone than keeping an\n        // CountingOutputStream reference around in addition to the FilterOutputStream's\n        // out.\n        return ((CountingOutputStream) out).getCount();\n    }*/\n}\n","sourceCodeStart":580,"sourceCodeEnd":611,"githubUrl":"https://github.com/Tencent/tinker/blob/1b7ea02c239840f563ea64fb5bd286eb98d4011e/third-party/tinker-ziputils/src/main/java/com/tencent/tinker/ziputils/ziputil/TinkerZipOutputStream.java#L580-L611","documentation":"checkSizeIsWithinShort() enforces that an entry's name (or comment) does not exceed 65535 bytes when encoded as UTF-8, because the zip format stores these lengths as 16-bit fields. It throws IllegalArgumentException(\"<property> too long in UTF-8:<n> bytes\") with property being \"Entry Name\" or similar, before the entry header is written.","triggerScenarios":"Calling putNextEntry() with an entry whose getName() encodes to more than 0xffff UTF-8 bytes (very deep paths or extremely long file names), or setting a comment longer than 64 KiB.","commonSituations":"Programmatically generated entry names (hash-based or concatenation-based) that grow unbounded; preserving absolute file-system paths as entry names; machine-generated comments; data migrated from formats without path-length limits.","solutions":["Shorten or hash the entry name before putNextEntry (e.g. keep the extension, hash the prefix).","If long names are inherent, truncate deterministically and keep a sidecar mapping of original name to entry name.","Validate nameBytes.length <= 0xffff in your own code and fail with a clear message identifying the offending entry."],"exampleFix":"// before\nString name = baseDir + \"/\" + veryLongGeneratedPath;\nzos.putNextEntry(new TinkerZipEntry(name)); // IllegalArgumentException\n\n// after\nString name = baseDir + \"/\" + veryLongGeneratedPath;\nif (name.getBytes(StandardCharsets.UTF_8).length > 0xffff) {\n    name = baseDir + \"/\" + sha1(veryLongGeneratedPath) + \".bin\";\n}\nzos.putNextEntry(new TinkerZipEntry(name));","handlingStrategy":"validation","validationCode":"static String safeEntryName(String name) {\n    if (name == null) return null;\n    byte[] b = name.getBytes(StandardCharsets.UTF_8);\n    return (b.length <= 0xffff) ? name : hashShorten(name); // deterministic fallback\n}\n// use: zos.putNextEntry(new TinkerZipEntry(safeEntryName(path)));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never use absolute filesystem paths as entry names","Fuzz-test generated names against the 64 KiB limit"],"tags":["zip","java","tinker","limits","entry-name"],"backgroundTag":null,"analyzedSha":"1b7ea02c239840f563ea64fb5bd286eb98d4011e","analyzedAt":"2026-08-14T15:16:52.110Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}