{"record":{"id":"23ddc6324b6e856e","repo":"JuliusBrussee/caveman","slug":"zstd-reader-w","errorCode":null,"errorMessage":"zstd reader: %w","messagePattern":"zstd reader: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/objectstore/compress.go","lineNumber":102,"sourceCode":"\t\t\treturn nil, fmt.Errorf(\"gzip 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\tcase CompressionZstd:\n\t\t// Zstd's smallest legal window is 1 KiB. Keep that parser minimum for\n\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":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/objectstore/compress.go#L84-L120","documentation":"DecompressLimit wraps zstd.NewReader construction failures with 'zstd reader:'. The library throws it when the zstd decoder cannot be created — practically only when the configured decoder memory limit (maxBytes-derived) is invalid. Unlike gzip, reader setup itself can fail here.","triggerScenarios":"Calling Decompress/DecompressLimit with CompressionZstd where the internal zstd.NewReader(nil, WithDecoderConcurrency(1), WithDecoderMaxMemory(memoryLimit)) call returns an error — typically a non-positive or absurdly small maxBytes producing an invalid decoder memory limit.","commonSituations":"Passing maxBytes=0 or a negative value that slips past upstream validation; constructing DecompressLimit arguments programmatically from config where the limit is unset (0).","solutions":["Pass a positive, sane maxBytes (>=1) to DecompressLimit so the decoder memory limit is valid.","Validate the limit from config before calling (reject 0/negative at config load).","If the error persists on valid input, check the klauspost/compress zstd dependency version for regressions."],"exampleFix":"// before\nout, err := objectstore.DecompressLimit(data, objectstore.CompressionZstd, cfg.MaxBytes) // cfg.MaxBytes == 0\n// after\nif cfg.MaxBytes <= 0 {\n    return fmt.Errorf(\"decompression limit must be positive, got %d\", cfg.MaxBytes)\n}\nout, err := objectstore.DecompressLimit(data, objectstore.CompressionZstd, cfg.MaxBytes)","handlingStrategy":"validation","validationCode":"if maxBytes <= 0 { return errors.New(\"decompression limit must be positive\") }","typeGuard":null,"tryCatchPattern":"out, err := objectstore.DecompressLimit(data, objectstore.CompressionZstd, maxBytes)\nif err != nil && !errors.Is(err, objectstore.ErrDecompressedTooLarge) {\n    return fmt.Errorf(\"zstd decoder setup failed, check maxBytes=%d: %w\", maxBytes, err)\n}","preventionTips":["Never pass a zero-valued int as maxBytes; apply defaults at config load.","Reject non-positive limits in your own config validation before use.","Pin and test the klauspost/compress version used by the library."],"tags":["zstd","decompression","invalid-argument"],"backgroundTag":"invalid-argument-value","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"}