Repository navigation
Name a rejected compression level or setting, and describe bzip2 and xz errors - #129519
Conversation
…compression level
`output_format_compression_level` (and `http_zlib_compression_level`) is passed
to the codec as is. zstd, lz4 and brotli clamp an out-of-range level, but zlib,
liblzma and bzip2 refuse it when the writer is created, and the writers turned
the library status into its own text, naming neither the level nor the codec:
deflateInit2 failed: stream error; zlib version: 1.3.1.zlib-ng. (ZLIB_DEFLATE_FAILED)
lzma preset failed: lzma version: 5.8.4. (LZMA_STREAM_ENCODER_FAILED)
bzip2 stream encoder init failed: error code: -2. (BZIP2_STREAM_ENCODER_FAILED)
This is what a gzip-compressed Iceberg metadata write at a zstd-valid level
(18) reported (item 3 of ClickHouse#126287).
With the fixed arguments these writers pass (method Z_DEFLATED, windowBits
15/31, memLevel 8, default strategy; bzip2 workFactor 0, verbosity 0; a
non-null stream), Z_STREAM_ERROR from deflateInit2, a failed lzma_lzma_preset
and BZ_PARAM_ERROR from BZ2_bzCompressInit each mean exactly "the level is
invalid". Those branches now throw "Compression level N is out of range for
<codec>" with the same error codes. The library still decides validity, so no
level that works today is rejected (gzip 0 and -1, xz 0 keep working), and no
range is quoted: the accepted set depends on the codec and on the
libdeflate/zlib split in createWriteCompressedWrapper, while
getCompressionLevelRange is the narrower documented INTO OUTFILE range.
Related: ClickHouse#126287
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…of_range `check()` grepped only the message text and dropped the client's exit status, so the test asserted neither that the statement fails nor that the error code is unchanged. It now matches `<message>. (<CODE>)` and prints `Unexpected success` when the client exits 0. The fast-test tag reason no longer lists xz, which is built unconditionally. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex) plus my own review, 2 rounds.
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-48:20261105-152600 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20261105-143400 |
|
cc @PedroTadim @rienath, could you review this and add the |
|
Workflow [PR], commit [e868ea7] Summary: ✅
AI ReviewSummaryPR #129519 improves diagnostics for rejected compression parameters and codec failures while preserving existing error codes and accepted values. Reviewed the current diff, surrounding callers, pinned library implementations, and all prior discussion. No actionable findings remain. Missing context / blind spots
Final VerdictStatus: ✅ Approve. No code changes requested; the full CI result remains pending. |
|
|
||
| int ret = BZ2_bzCompressInit(&stream, compression_level, 0, 0); | ||
|
|
||
| if (ret == BZ_PARAM_ERROR) |
There was a problem hiding this comment.
@groeneai just quickly check if we are missing any other possible error check from the compression/codec libraries/submodules that we use
There was a problem hiding this comment.
I checked every user-tunable parameter that reaches a compression library by running it (file() writes for each codec at levels up to 2^32, Parquet with both encoders, CODEC(...) arguments, BACKUP to zip, zstd window logs). Two more places returned the bare library status. Both are fixed in df49f80 the same way (the library decides, the message names the value, the error code is kept), and the description and changelog entry are updated:
- reading a
.zstfile withzstd_window_log_maxoutside 10..31:zstd_stream_decoder init failed: Parameter is out of bound->Setting zstd_window_log_max = 9 is out of range for zstd BACKUP ... TO Disk(..., 'x.zip')withcompression_methoddeflate/bzip2/lzma/xz andcompression_leveloutside -1..9:Couldn't pack zip archive: Code = -111->Compression level 10 is out of range for deflate
The rest needs nothing: zstd, lz4 and brotli clamp the level, snappy has none, and output_format_compression_zstd_window_log, codec arguments and network_zstd_compression_level (through the codec factory) already fail with a clear message. Not touched: output_format_compression_level is UInt64 and the callers cast it to int, so a value above 2^31 wraps before any library sees it (4294967296 becomes level 0).
Two more places reported an invalid user-supplied compression parameter with
the library status only:
zstd_stream_decoder init failed: Parameter is out of bound. (ZSTD_DECODER_FAILED)
Couldn't pack zip archive: Code = -111, filename='metadata/default/t.sql'. (CANNOT_PACK_ARCHIVE)
The first is `zstd_window_log_max` outside 10..31 (0 is the default) on a read
of a zstd file: on a fresh decoder context,
ZSTD_DCtx_setParameter(ZSTD_d_windowLogMax) fails only with
parameter_outOfBound. The second is BACKUP to a zip archive with
`compression_method` deflate, bzip2, lzma or xz and a `compression_level`
outside -1..9: minizip-ng maps -1 to the default and 0 to store, and returns
MZ_OPEN_ERROR when zlib, bzip2 or liblzma refuses the level. zstd clamps the
level and store ignores it, so neither is touched.
They now say "Setting zstd_window_log_max = 9 is out of range for zstd" and
"Compression level 10 is out of range for deflate", with the same error codes.
The library still decides, so no value that works today is rejected.
The other user-tunable parameters were checked by running them: zstd, lz4
and brotli clamp the level, snappy has none, and
`output_format_compression_zstd_window_log`, column codecs and
`network_zstd_compression_level` (codec factory) already fail with a clear
message.
Related: ClickHouse#126287
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Asked in review: errors from the bzip2 and xz readers and writers printed the bare library return code (`bzip2 stream decoder failed: error code: -5`, `lzma_stream_decoder failed: error code: error code LZMA_FORMAT_ERROR`), since neither library has a counterpart of zlib's zError(). Each status now has a description, worded after the library's own command-line tool, followed by the status name: `bzip2 stream decoder failed: Not a bzip2 stream (BZ_DATA_ERROR_MAGIC)`. Statuses a user can reach by reading a damaged file: BZ_DATA_ERROR, BZ_DATA_ERROR_MAGIC, LZMA_DATA_ERROR, LZMA_FORMAT_ERROR, LZMA_BUF_ERROR (truncated input) and LZMA_MEMLIMIT_ERROR (a stream needing more than the decoder's 500 MiB limit). The others are init or sequence failures and get the same treatment for uniformity. The two zstd encoder sites that printed the size_t return value now use ZSTD_getErrorName(), like the other zstd sites. zlib already uses zError(). Error codes are unchanged. Also fixes the bzip2 reader calling itself an encoder in its messages. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…sage Asked in review: with bzip2ErrorToString() and ZSTD_getErrorName() describing the library status, the branches special-casing BZ_PARAM_ERROR after BZ2_bzCompressInit() and parameter_outOfBound after ZSTD_DCtx_setParameter(windowLogMax) are not needed. Those are the only statuses the two calls can return for a user value (the other bzip2 arguments are fixed, the decoder context is fresh), so the remaining message now names the value instead: bzip2 stream encoder init failed for compression level 0: Invalid parameter (BZ_PARAM_ERROR) zstd_stream_decoder init failed for zstd_window_log_max = 9: Parameter is out of bound The gzip, deflate, xz and zip branches stay: zlib describes Z_STREAM_ERROR only as "stream error", lzma_lzma_preset() returns a bool, and minizip-ng reports the refused level as MZ_OPEN_ERROR. Error codes are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes14 object files changed (-44.30 KiB total), 1 added.
719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units19 translation units recompiled, 22 s compile time in total, 18 of them have a recent master baseline. |
|
🕵️ @groeneai Looks good. Three small things:
|
…messages liblzma gives LZMA_DATA_ERROR and LZMA_BUF_ERROR different meanings in encoders (the output would exceed the xz format's size limits; no progress is possible) and decoders (corrupt data; unexpected end of input), so lzmaErrorToString takes an is_encoder flag. ZstdDeflatingAppendableWriteBuffer said "decoding" in the encoder, and the xz reader printed LZMA_STREAM_END as "error code: 1" when the decoder finishes before the input ends; it now says there is trailing data. The zip writer comment now says why -1..9 is the refused range for every method: minizip-ng stores an entry at level 0 (mz_zip.c), so bzip2 never sees level 0. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks. Points 2 and 3 are fixed in d689af4, test in e868ea7.
|
Related: #126287
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
A compression level that
gzip,deflate,xzor aBACKUPto a zip archive does not accept (for exampleoutput_format_compression_level = 18for a.gzfile or for gzip-compressed Iceberg metadata) now fails withCompression level 18 is out of range for gzipinstead of a codec library message such asdeflateInit2 failed: stream error. A rejectedbz2level orzstd_window_log_maxis now named in the error, for examplezstd_stream_decoder init failed for zstd_window_log_max = 9: Parameter is out of bound.bz2andxzerrors describe the library status (for exampleNot a bzip2 stream (BZ_DATA_ERROR_MAGIC)) instead of a number. Error codes are unchanged.Description
Item 3 of #126287.
output_format_compression_level(andhttp_zlib_compression_level) is passed to the codec as is. zstd, lz4 and brotli clamp an out-of-range level; zlib, liblzma and bzip2 refuse it, and the error named neither the level nor the codec:Same for
.xz,.bz2, gzip Iceberg metadata,BACKUPto a zip archive withcompression_methoddeflate/bzip2/lzma/xz (Couldn't pack zip archive: Code = -111), and a zstd read withzstd_window_log_maxoutside 10..31 (Parameter is out of bound).bzip2 and liblzma have no
zError, so their other statuses printed as numbers (bzip2 stream decoder failed: error code: -5for a damaged file); they now print a description and the status name, with the encoder meaning ofLZMA_DATA_ERROR/LZMA_BUF_ERRORin the xz writer. Two zstd encoder sites useZSTD_getErrorNameinstead of the rawsize_t, a third no longer says "decoding", and the xz reader no longer printsLZMA_STREAM_ENDaserror code: 1.Change: where the library's text for the "invalid value" status says nothing (
Z_STREAM_ERRORisstream error,lzma_lzma_presetreturns a bool, minizip-ng returnsMZ_OPEN_ERRORfor a level outside -1..9), the error is nowCompression level N is out of range for <codec>; bzip2 and the zstd decoder name the value next to the library status. The library still decides what is valid.Not changed: up-front validation against
getCompressionLevelRangewould newly reject gzip 0 and xz 0; the codec default for Iceberg metadata would silently ignore the setting. Items 1 and 2 are a separate PR.Validation:
05508_compression_level_out_of_rangecovers the level, setting and damaged-input cases; it fails on master, passes with the fix, 50/50 randomized runs. Accepted levels round-trip identically on master and here.Workflow [PR]
Sync PR [sync-upstream/pr/129519]
Version info
26.11.1.1497-master(included in26.11and later)