{"record":{"id":"c1587731ccf5cf7d","repo":"Tencent/tinker","slug":"bad-size-value","errorCode":null,"errorMessage":"Bad size: ${value}","messagePattern":"Bad size: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"third-party/tinker-ziputils/src/main/java/com/tencent/tinker/ziputils/ziputil/TinkerZipEntry.java","lineNumber":351,"sourceCode":"    /**\n     * Gets the uncompressed size of this {@code ZipEntry}.\n     *\n     * @return the uncompressed size, or {@code -1} if the size has not been\n     *         set.\n     */\n    public long getSize() {\n        return size;\n    }\n\n    /**\n     * Sets the uncompressed size of this {@code ZipEntry}.\n     *\n     * @param value the uncompressed size for this entry.\n     * @throws IllegalArgumentException if {@code value < 0}.\n     */\n    public void setSize(long value) {\n        if (value < 0) {\n            throw new IllegalArgumentException(\"Bad size: \" + value);\n        }\n        size = value;\n    }\n\n    /**\n     * Gets the last modification time of this {@code ZipEntry}.\n     *\n     * @return the last modification time as the number of milliseconds since\n     *         Jan. 1, 1970.\n     */\n    public long getTime() {\n        if (time != -1) {\n            GregorianCalendar cal = new GregorianCalendar();\n            cal.set(Calendar.MILLISECOND, 0);\n            cal.set(1980 + ((modDate >> 9) & 0x7f), ((modDate >> 5) & 0xf) - 1,\n                    modDate & 0x1f, (time >> 11) & 0x1f, (time >> 5) & 0x3f,\n                    (time & 0x1f) << 1);\n            return cal.getTime().getTime();","sourceCodeStart":333,"sourceCodeEnd":369,"githubUrl":"https://github.com/Tencent/tinker/blob/1b7ea02c239840f563ea64fb5bd286eb98d4011e/third-party/tinker-ziputils/src/main/java/com/tencent/tinker/ziputils/ziputil/TinkerZipEntry.java#L333-L369","documentation":"setSize sets the uncompressed size of an entry, which the zip format stores as a non-negative quantity. A negative value throws IllegalArgumentException('Bad size'). Note this library's guard is only value < 0 — unlike the Harmony/Android original it does not enforce the 32-bit zip1 limit here, but a negative size always indicates uninitialized or corrupted state in the caller (e.g. -1 'unknown' sentinel).","triggerScenarios":"Calling setSize(value) with value < 0, most commonly forwarding -1 from an API that uses -1 to mean 'size unknown' (java.util.zip.ZipEntry.getSize returns -1 when unset), or a subtraction that underflowed.","commonSituations":"Reading sizes from a parsed central directory where the field failed to parse; copying from a source entry whose size was never set; using -1 as a placeholder before the real size is known.","solutions":["Only call setSize when you have a real non-negative size; skip the call entirely if the source reports -1 (unknown).","Compute sizes from the actual data (e.g. after reading the stream) rather than propagating sentinels.","Check for -1 explicitly and throw your own descriptive error upstream, so the failure is not buried in the zip writer."],"exampleFix":"// before\nlong srcSize = sourceEntry.getSize(); // -1 when unset\nnewEntry.setSize(srcSize);\n\n// after\nlong srcSize = sourceEntry.getSize();\nif (srcSize >= 0) {\n    newEntry.setSize(srcSize);\n}","handlingStrategy":"validation","validationCode":"long sz = sourceEntry.getSize();\nif (sz >= 0) {\n    newEntry.setSize(sz);\n}\n// skip the call when sz == -1 (unknown)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat -1 from getSize() as 'unknown' and omit the setSize call.","Compute sizes from actual data when the source does not provide them.","Never use negative sentinels as placeholder sizes in your own entry model."],"tags":["zip","validation","size","tinker"],"backgroundTag":null,"analyzedSha":"1b7ea02c239840f563ea64fb5bd286eb98d4011e","analyzedAt":"2026-08-14T15:16:52.110Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}