{"record":{"id":"1aaa138ada84fcbe","repo":"juicedata/juicefs","slug":"decompress-an-empty-input","errorCode":null,"errorMessage":"decompress an empty input","messagePattern":"decompress an empty input","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/compress/compress.go","lineNumber":122,"sourceCode":"\n// LZ4 implements Compressor using LZ4 library\ntype LZ4 struct{}\n\n// Name returns name of the algorithm LZ4\nfunc (l LZ4) Name() string { return \"LZ4\" }\n\n// CompressBound max size of compressed data\nfunc (l LZ4) CompressBound(size int) int { return lz4.CompressBound(size) }\n\n// Compress using LZ4 algorithm\nfunc (l LZ4) Compress(dst, src []byte) (int, error) {\n\treturn lz4.CompressDefault(src, dst)\n}\n\n// Decompress using LZ4 algorithm\nfunc (l LZ4) Decompress(dst, src []byte) (int, error) {\n\tif len(src) == 0 {\n\t\treturn 0, fmt.Errorf(\"decompress an empty input\")\n\t}\n\treturn lz4.DecompressSafe(src, dst)\n}\n","sourceCodeStart":104,"sourceCodeEnd":126,"githubUrl":"https://github.com/juicedata/juicefs/blob/c9a67b23e8e08ec23ec331aa6f1675e2319e921c/pkg/compress/compress.go#L104-L126","documentation":"Returned by LZ4.Decompress when the input buffer is empty. LZ4 has no representation for zero-length compressed data, so decompressing nothing is treated as invalid input rather than returning zero bytes.","triggerScenarios":"Calling LZ4.Decompress(dst, src) with len(src) == 0 — e.g. a zero-length compressed block read from object storage or cache, or passing an empty/nil slice directly.","commonSituations":"Corrupt or truncated uploads producing 0-byte blocks; volume formatted with lz4 compression but a block was stored empty; bugs in callers that skip empty-data checks before decompressing.","solutions":["Check for empty input before decompressing and handle it as a valid empty payload (or skip).","Investigate why a 0-byte compressed block exists: verify the object in object storage, re-upload or repair the block.","Use `juicefs gc`/fsck-style tooling to find and clean corrupt or empty blocks."],"exampleFix":"// before\nn, err := comp.Decompress(dst, src) // panics/errors when src empty\n\n// after\nif len(src) == 0 {\n    return 0, nil // empty payload is valid\n}\nn, err := comp.Decompress(dst, src)","handlingStrategy":"validation","validationCode":"if len(src) == 0 { /* treat as empty payload; skip decompress */ }","typeGuard":null,"tryCatchPattern":"n, err := comp.Decompress(dst, src)\nif err != nil && strings.Contains(err.Error(), \"empty input\") {\n    return handleEmptyBlock() // or flag corrupt block for repair\n}","preventionTips":["Guard len(src)==0 before decompressing","Investigate any 0-byte compressed objects in storage — they indicate corrupt/truncated uploads","Enable integrity checks on upload paths"],"tags":["compression","lz4","empty-input"],"backgroundTag":"empty-required-field","analyzedSha":"c9a67b23e8e08ec23ec331aa6f1675e2319e921c","analyzedAt":"2026-09-06T17:55:48.476Z","contentChangedAt":"2026-09-06T17:55:48.476Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}