{"record":{"id":"65ce3f697d7e38f7","repo":"containerd/containerd","slug":"unsupported-compression-format-s","errorCode":null,"errorMessage":"unsupported compression format %s","messagePattern":"unsupported compression format (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/archive/compression/compression.go","lineNumber":240,"sourceCode":"\t\t}, nil\n\tcase Zstd:\n\t\tzstdReader, err := zstd.NewReader(buf,\n\t\t\tzstd.WithDecoderLowmem(false),\n\t\t)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\treturn &readCloserWrapper{\n\t\t\tReader:      zstdReader,\n\t\t\tcompression: compression,\n\t\t\tcloser: func() error {\n\t\t\t\tzstdReader.Close()\n\t\t\t\treturn nil\n\t\t\t},\n\t\t}, nil\n\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"unsupported compression format %s\", (&compression).Extension())\n\t}\n}\n\n// CompressStream compresses the dest with specified compression algorithm.\nfunc CompressStream(dest io.Writer, compression Compression) (io.WriteCloser, error) {\n\tswitch compression {\n\tcase Uncompressed:\n\t\treturn &writeCloserWrapper{dest, nil}, nil\n\tcase Gzip:\n\t\treturn gzip.NewWriter(dest), nil\n\tcase Zstd:\n\t\treturn zstd.NewWriter(dest)\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"unsupported compression format %s\", (&compression).Extension())\n\t}\n}\n\n// Extension returns the extension of a file that uses the specified compression algorithm.","sourceCodeStart":222,"sourceCodeEnd":258,"githubUrl":"https://github.com/containerd/containerd/blob/4246446a2bf7d03837b0244118d858799393bd80/pkg/archive/compression/compression.go#L222-L258","documentation":"DecompressStream dispatches on the Compression value to create a decompressing io.Reader. The default branch fires when the compression value is not one of the supported algorithms (Uncompressed, Gzip, Bzip2, Xz, Zstd, etc.), producing this error with the compression's Extension() name. It indicates an unknown/invalid Compression constant.","triggerScenarios":"Calling DecompressStream(reader) with a Compression value outside the known set — e.g. a zero-value Compression not equal to Uncompressed, a corrupted/discovered media-type mapping yielding an undefined algorithm, or an integer-constructed Compression.","commonSituations":"Pulling/parsing layer descriptors whose media type maps to an unknown algorithm; hand-constructing Compression from an int; a newer image format compressed with an algorithm this containerd/compression build doesn't know (version mismatch); passing the result of DetectCompression on garbage input.","solutions":["Use a valid Compression constant from the package (Uncompressed, Gzip, Bzip2, Xz, Zstd) rather than a raw value","Check the source media type / Content-Type that produced the Compression value and ensure the mapping is correct","Upgrade the compression package/containerd to a version supporting the format in question","If decompressing user input, validate the detected compression before calling DecompressStream"],"exampleFix":"// before\nc := compression.Compression(7)\nr, err := compression.DecompressStream(reader) // unsupported\n// after\nif c != compression.Uncompressed && c != compression.Gzip && c != compression.Zstd { /* handle */ }\nr, err := compression.DecompressStream(reader)","handlingStrategy":"validation","validationCode":"func knownCompression(c compression.Compression) bool {\n\tswitch c {\n\tcase compression.Uncompressed, compression.Gzip, compression.Bzip2, compression.Xz, compression.Zstd:\n\t\treturn true\n\t}\n\treturn false\n}\nif !knownCompression(c) { return fmt.Errorf(\"unknown compression %v\", c) }","typeGuard":"func isKnown(c compression.Compression) bool {\n\treturn c == compression.Uncompressed || c == compression.Gzip || c == compression.Zstd\n}","tryCatchPattern":"r, err := compression.DecompressStream(reader)\nif err != nil {\n\tif strings.Contains(err.Error(), \"unsupported compression format\") {\n\t\t// fall back to reading raw or upgrade client for newer formats\n\t}\n\treturn err\n}","preventionTips":["Derive Compression only from package constants, never int casts","Validate media types against supported algorithms before mapping","Keep the compression package updated for newer formats"],"tags":["compression","archive","unsupported-format","image-layers"],"backgroundTag":"unsupported-compression-format","analyzedSha":"4246446a2bf7d03837b0244118d858799393bd80","analyzedAt":"2026-09-02T00:14:43.053Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}