{"record":{"id":"b1bc80bc3de3813d","repo":"JuliusBrussee/caveman","slug":"zstd-read-w","errorCode":null,"errorMessage":"zstd read: %w","messagePattern":"zstd read: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/objectstore/compress.go","lineNumber":110,"sourceCode":"\t\t// tiny valid payloads, then independently enforce the exact byte limit.\n\t\tmemoryLimit := uint64(maxBytes)\n\t\tif memoryLimit < zstd.MinWindowSize {\n\t\t\tmemoryLimit = zstd.MinWindowSize\n\t\t}\n\t\tzr, err := zstd.NewReader(nil,\n\t\t\tzstd.WithDecoderConcurrency(1),\n\t\t\tzstd.WithDecoderMaxMemory(memoryLimit),\n\t\t)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"zstd reader: %w\", err)\n\t\t}\n\t\tdefer zr.Close()\n\t\tout, err := zr.DecodeAll(data, nil)\n\t\tif err != nil {\n\t\t\tif errors.Is(err, zstd.ErrDecoderSizeExceeded) || errors.Is(err, zstd.ErrWindowSizeExceeded) {\n\t\t\t\treturn nil, ErrDecompressedTooLarge\n\t\t\t}\n\t\t\treturn nil, fmt.Errorf(\"zstd read: %w\", err)\n\t\t}\n\t\tif int64(len(out)) > maxBytes {\n\t\t\treturn nil, ErrDecompressedTooLarge\n\t\t}\n\t\treturn out, nil\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"unknown compression codec %q\", codec)\n\t}\n}\n","sourceCodeStart":92,"sourceCodeEnd":120,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/objectstore/compress.go#L92-L120","documentation":"DecompressLimit wraps zstd.DecodeAll failures with 'zstd read:' when the error is not the recognized size/window limit errors (those are translated to ErrDecompressedTooLarge). It means the zstd payload itself failed to decode: corrupt, truncated, or not zstd data.","triggerScenarios":"Calling Decompress/DecompressLimit with CompressionZstd on bytes that are not a valid complete zstd frame — wrong codec label, truncated upload, bit rot, or data compressed with a different algorithm.","commonSituations":"Objects written by another tool with a raw/legacy zstd framing; metadata says zstd but body is gzip or plain; interrupted multipart uploads; disk corruption.","solutions":["Verify the payload magic (zstd frames start with 0x28 0xB5 0x2F 0xFD) and that the stored codec label matches.","Re-fetch/re-upload the object; the stored bytes are likely truncated or corrupted.","Confirm the producer used the same zstd library/framing (klauspost/compress DecodeAll expects standard frames).","Test the same blob with an independent zstd decoder (e.g. `zstd -t file`) to confirm corruption."],"exampleFix":"// before\nout, err := objectstore.DecompressLimit(blob, objectstore.CompressionZstd, limit) // blob is gzip, metadata says zstd\n// after\nif len(blob) < 4 || binary.LittleEndian.Uint32(blob) != 0xFD2FB528 {\n    return fmt.Errorf(\"blob is not zstd; fix codec metadata\")\n}\nout, err := objectstore.DecompressLimit(blob, objectstore.CompressionZstd, limit)","handlingStrategy":"validation","validationCode":"func isZstd(b []byte) bool { return len(b) >= 4 && binary.LittleEndian.Uint32(b) == 0xFD2FB528 }","typeGuard":"func isZstd(b []byte) bool { return len(b) >= 4 && binary.LittleEndian.Uint32(b) == 0xFD2FB528 }","tryCatchPattern":"out, err := objectstore.DecompressLimit(data, objectstore.CompressionZstd, limit)\nswitch {\ncase errors.Is(err, objectstore.ErrDecompressedTooLarge): // over-limit path\ncase err != nil: return fmt.Errorf(\"zstd payload corrupt or wrong codec: %w\", err)\n}","preventionTips":["Store the codec in object metadata and honor it; never hardcode.","Verify the zstd magic before decoding unknown blobs.","Re-upload corrupted objects; do not retry the same bytes."],"tags":["zstd","decompression","corrupt-data"],"backgroundTag":"file-read-failed","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}