commaai/openpilot · error · ValueError
Unsupported compression type: {compression}
Error message
Unsupported compression type: {compression} What it means
make_decompressor() only accepts 'bz2' and 'zst'. decompress_file() passes either the caller-supplied compression argument or the value sniffed from the 4-byte header (compression_type returns None for unknown magic). A None or unknown value reaching make_decompressor raises this ValueError, meaning the caller forced a bad compression name or the file magic was unrecognized and None propagated.
Source
Thrown at openpilot/tools/lib/file_downloader.py:66
if compression:
url_without_query = f"decompressed-{compression}:{url_without_query}"
return os.path.join(Paths.download_cache_root(), hashlib.sha256(url_without_query.encode()).hexdigest())
def compression_type(data):
if data.startswith(b'BZh'):
return 'bz2'
if data.startswith(b'\x28\xb5\x2f\xfd'):
return 'zst'
return None
def make_decompressor(compression):
if compression == 'bz2':
return bz2.BZ2Decompressor()
if compression == 'zst':
return zstd.ZstdDecompressor().decompressobj()
raise ValueError(f"Unsupported compression type: {compression}")
def decompress_file(source, destination, compression=None):
with open(source, 'rb') as src, open(destination, 'wb') as dst:
header = src.read(4)
compression = compression or compression_type(header)
decompressor = make_decompressor(compression)
dst.write(decompressor.decompress(header))
while data := src.read(1024 * 1024):
dst.write(decompressor.decompress(data))
if not decompressor.eof:
raise EOFError(f"Compressed {compression} file ended before the end-of-stream marker")
def materialize_cached_file(source, url, compression):
local_path = cache_file_path(url, compression)
if os.path.exists(local_path):
return local_pathView on GitHub (pinned to 516ec1e682)
Solutions
- If you know the true format, pass it explicitly: decompress_file(src, dst, compression='bz2') - but only bz2/zst are supported
- For gzip/xz, decompress outside this helper (gzip module / lzma module) - it deliberately supports only bz2 and zstd
- Check the first 4 bytes of the file (xxd | head) to see whether the magic matches what you claimed
Example fix
# before
decompress_file(src, dst, compression='gzip')
# after (gzip is unsupported here - use the stdlib)
import gzip
with gzip.open(src, 'rb') as f_in, open(dst, 'wb') as f_out:
shutil.copyfileobj(f_in, f_out) Defensive patterns
Strategy: validation
Validate before calling
comp = compression if compression else compression_type(open(source, 'rb').read(4))
assert comp in ('bz2', 'zst'), f"unsupported/undetected compression {comp!r}; this helper handles only bz2 and zst" Type guard
def is_supported_compression(name: str | None) -> bool:
"""True when name is one of the decompressor's supported formats."""
return name in ('bz2', 'zst') Try / catch
try:
decompress_file(src, dst, compression=comp)
except ValueError as e:
if 'Unsupported compression' in str(e):
raise SystemExit(f'{comp} not supported; use gzip/lzma modules for other formats')
raise Prevention
- Sniff the 4-byte magic yourself and route gzip/xz/plain files to the appropriate stdlib module
- Never hardcode a compression name without verifying the file's magic bytes first
When it happens
Trigger: Calling decompress_file(..., compression='gzip') or 'xz'; passing compression=None on a file whose first 4 bytes are neither BZh ('BZh') nor the zstd magic 0x28B52FFD; corrupt header bytes.
Common situations: Server starts serving gzip/plain data while the client assumed bz2; truncated download losing the magic bytes; hardcoded compression name drifting from actual format.
Related errors
- invalid config backup: {backup}
- No camera file for segment {seg_idx}
- No valid camera paths
- Function body is empty
- No reference series found. Set an input timeseries or return
AI-assisted analysis of commaai/openpilot@516ec1e682 (2026-08-15).
Data as JSON: /api/errors/4f53d589bd9aac78.
Report an issue: GitHub.