std/brotli: let a shorter encoder workbuf work for short inputs

Move the ring buffer to the end of the workbuf layout (at qualities 2 to
9). A workbuf shorter than workbuf_len now works if it holds the input
so far (plus 16 bytes of slack) in the ring buffer region and the input
stays short enough for the ring buffer never to wrap. This matters most
for large-window brotli, where workbuf_len at lgwin 30 is more than
2 GiB, mostly for a ring buffer that short inputs never touch.

The parity harness now also checks its large-window configurations with
the shortest such workbuf (and that one byte less fails).
This commit is contained in:
Claude committed 2026-10-27 02:36:23 +00:00
1 parent fd89148c0b
commit 0b9cfddf3c
5 files changed
+262 -61

No files matched your search

+57 -43
View File
@@ -10010,6 +10010,7 @@ struct wuffs_brotli__encoder__struct {
uint32_t f_rb_total_size;
uint32_t f_rb_cur_size;
uint32_t f_rb_pos;
bool f_rb_short_workbuf;
uint32_t f_dist_alphabet_size_max;
uint32_t f_dist_alphabet_size_limit;
uint64_t f_dist_max_distance;
@@ -68498,30 +68499,32 @@ WUFFS_BROTLI__DICTIONARY[122784] WUFFS_BASE__POTENTIALLY_UNUSED = {
#define WUFFS_BROTLI__LAYOUT_STORAGE 0u
#define WUFFS_BROTLI__LAYOUT_RB 1u
#define WUFFS_BROTLI__LAYOUT_HASH 1u
#define WUFFS_BROTLI__LAYOUT_HASH 2u
#define WUFFS_BROTLI__LAYOUT_CMDS 2u
#define WUFFS_BROTLI__LAYOUT_CMDS 3u
#define WUFFS_BROTLI__LAYOUT_TYPES_0 3u
#define WUFFS_BROTLI__LAYOUT_TYPES_0 4u
#define WUFFS_BROTLI__LAYOUT_LENGTHS_0 6u
#define WUFFS_BROTLI__LAYOUT_LENGTHS_0 7u
#define WUFFS_BROTLI__LAYOUT_HISTO_0 9u
#define WUFFS_BROTLI__LAYOUT_HISTO_0 10u
#define WUFFS_BROTLI__LAYOUT_COMB 12u
#define WUFFS_BROTLI__LAYOUT_COMB 13u
#define WUFFS_BROTLI__LAYOUT_CMAP 13u
#define WUFFS_BROTLI__LAYOUT_CMAP 14u
#define WUFFS_BROTLI__LAYOUT_RLE 14u
#define WUFFS_BROTLI__LAYOUT_RLE 15u
#define WUFFS_BROTLI__LAYOUT_BE_DEPTH_0 15u
#define WUFFS_BROTLI__LAYOUT_BE_DEPTH_0 16u
#define WUFFS_BROTLI__LAYOUT_BE_BITS_0 18u
#define WUFFS_BROTLI__LAYOUT_BE_BITS_0 19u
#define WUFFS_BROTLI__LAYOUT_RB 21u
#define WUFFS_BROTLI__LAYOUT_END 22u
#define WUFFS_BROTLI__RB_SHORT_SLACK 16u
#define WUFFS_BROTLI__MAX_NUM_DELAYED_SYMBOLS 12287u
#define WUFFS_BROTLI__F64_0_99 4607092346807469998u
@@ -79349,6 +79352,7 @@ wuffs_brotli__encoder__transform_io(
uint64_t v_remaining = 0;
bool v_injected = false;
uint64_t v_copy_input_size = 0;
uint64_t v_total = 0;
uint8_t* iop_a_dst = NULL;
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
@@ -79392,8 +79396,11 @@ wuffs_brotli__encoder__transform_io(
status = wuffs_base__make_status(wuffs_brotli__error__unsupported_encoder_quality);
goto exit;
} else if ((self->private_impl.f_quality >= 2u) && (((uint64_t)(a_workbuf.len)) < self->private_impl.f_workbuf_end)) {
status = wuffs_base__make_status(wuffs_base__error__bad_workbuf_length);
goto exit;
self->private_impl.f_rb_short_workbuf = true;
if (((uint64_t)(a_workbuf.len)) < ((uint64_t)(self->private_impl.f_rb_buf_off + 16u))) {
status = wuffs_base__make_status(wuffs_base__error__bad_workbuf_length);
goto exit;
}
}
while (true) {
if (self->private_impl.f_metadata_requested) {
@@ -79491,6 +79498,13 @@ wuffs_brotli__encoder__transform_io(
}
if ((v_remaining != 0u) && (((uint64_t)(io2_a_src - iop_a_src)) > 0u)) {
v_copy_input_size = wuffs_base__u64__min(v_remaining, ((uint64_t)(io2_a_src - iop_a_src)));
if (self->private_impl.f_rb_short_workbuf) {
v_total = ((uint64_t)(((uint64_t)(self->private_impl.f_input_pos + v_copy_input_size)) + 16u));
if ((v_total > ((uint64_t)(self->private_impl.f_rb_size))) || (((uint64_t)(self->private_impl.f_rb_buf_off + v_total)) > ((uint64_t)(a_workbuf.len)))) {
status = wuffs_base__make_status(wuffs_base__error__bad_workbuf_length);
goto exit;
}
}
v_mark = ((uint64_t)(iop_a_src - io0_a_src));
self->private_data.s_transform_io.scratch = v_copy_input_size;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
@@ -80502,49 +80516,49 @@ wuffs_brotli__encoder__compute_layout_offset(
v_size = 0u;
if (v_i == 0u) {
v_size = ((uint64_t)(((uint64_t)(((uint64_t)(2u * v_max_len)) + 503u)) + 16u));
} else if (v_i == 1u) {
} else if (v_i == 21u) {
v_size = ((uint64_t)(((uint64_t)((2u + (((uint64_t)(1u)) << wuffs_brotli__encoder__rb_bits(self, a_lgwin, a_lgblock))) + (((uint64_t)(1u)) << a_lgblock))) + 7u));
} else if (v_i == 2u) {
} else if (v_i == 1u) {
v_size = wuffs_brotli__encoder__hash_region_size(self, a_quality, a_lgwin);
} else if (v_i == 3u) {
} else if (v_i == 2u) {
v_size = ((uint64_t)(16u * v_cmds_cap));
} else if (a_quality >= 4u) {
if (v_i == 4u) {
if (v_i == 3u) {
v_size = ((v_max_len / 512u) + 1u);
} else if (v_i == 5u) {
} else if (v_i == 4u) {
v_size = ((uint64_t)((v_cmds_cap / 1024u) + 1u));
} else if (v_i == 6u) {
} else if (v_i == 5u) {
v_size = ((uint64_t)((v_cmds_cap / 512u) + 1u));
} else if (v_i == 7u) {
} else if (v_i == 6u) {
v_size = (4u * ((v_max_len / 512u) + 1u));
} else if (v_i == 8u) {
} else if (v_i == 7u) {
v_size = ((uint64_t)(4u * ((uint64_t)((v_cmds_cap / 1024u) + 1u))));
} else if (v_i == 9u) {
} else if (v_i == 8u) {
v_size = ((uint64_t)(4u * ((uint64_t)((v_cmds_cap / 512u) + 1u))));
} else if ((10u <= v_i) && (v_i < 13u)) {
if (v_i == 10u) {
} else if ((9u <= v_i) && (v_i < 12u)) {
if (v_i == 9u) {
v_size = 266240u;
} else if (v_i == 11u) {
} else if (v_i == 10u) {
v_size = 723712u;
} else {
v_size = 559232u;
}
} else if (v_i == 13u) {
} else if (v_i == 12u) {
v_size = 26624u;
} else if (v_i == 14u) {
} else if (v_i == 13u) {
v_size = 16384u;
} else if (v_i == 15u) {
} else if (v_i == 14u) {
v_size = 65536u;
} else if ((16u <= v_i) && (v_i < 22u)) {
} else if ((15u <= v_i) && (v_i < 21u)) {
v_num_histo = 256u;
v_hlen = 256u;
if ((v_i == 17u) || (v_i == 20u)) {
if ((v_i == 16u) || (v_i == 19u)) {
v_hlen = 704u;
} else if ((v_i == 18u) || (v_i == 21u)) {
} else if ((v_i == 17u) || (v_i == 20u)) {
v_hlen = 544u;
}
v_size = ((uint64_t)(v_num_histo * v_hlen));
if (v_i >= 19u) {
if (v_i >= 18u) {
v_size = ((uint64_t)(2u * v_size));
}
}
@@ -80573,18 +80587,18 @@ wuffs_brotli__encoder__compute_layout(
v_q,
v_lw,
v_lb,
1u);
21u);
self->private_impl.f_rb_buf_off = ((uint64_t)(self->private_impl.f_rb_off + 2u));
self->private_impl.f_h_off0 = wuffs_brotli__encoder__compute_layout_offset(self,
v_q,
v_lw,
v_lb,
2u);
1u);
self->private_impl.f_cmds_off = wuffs_brotli__encoder__compute_layout_offset(self,
v_q,
v_lw,
v_lb,
3u);
2u);
self->private_impl.f_cmds_cap = wuffs_brotli__encoder__commands_capacity(self, v_q, v_lw, v_lb);
v_c = 0u;
while (v_c < 3u) {
@@ -80592,44 +80606,44 @@ wuffs_brotli__encoder__compute_layout(
v_q,
v_lw,
v_lb,
(4u + v_c));
(3u + v_c));
self->private_data.f_gbs_lengths_off[v_c] = wuffs_brotli__encoder__compute_layout_offset(self,
v_q,
v_lw,
v_lb,
(7u + v_c));
(6u + v_c));
self->private_data.f_gbs_histo_off_base[v_c] = wuffs_brotli__encoder__compute_layout_offset(self,
v_q,
v_lw,
v_lb,
(10u + v_c));
(9u + v_c));
self->private_data.f_be_depth_off[v_c] = wuffs_brotli__encoder__compute_layout_offset(self,
v_q,
v_lw,
v_lb,
(16u + v_c));
(15u + v_c));
self->private_data.f_be_bits_off[v_c] = wuffs_brotli__encoder__compute_layout_offset(self,
v_q,
v_lw,
v_lb,
(19u + v_c));
(18u + v_c));
v_c += 1u;
}
self->private_impl.f_mb_comb_off = wuffs_brotli__encoder__compute_layout_offset(self,
v_q,
v_lw,
v_lb,
13u);
12u);
self->private_impl.f_mb_cmap_off = wuffs_brotli__encoder__compute_layout_offset(self,
v_q,
v_lw,
v_lb,
14u);
13u);
self->private_impl.f_mb_rle_off = wuffs_brotli__encoder__compute_layout_offset(self,
v_q,
v_lw,
v_lb,
15u);
14u);
self->private_impl.f_workbuf_end = wuffs_brotli__encoder__compute_layout_offset(self,
v_q,
v_lw,
+106 -2
View File
@@ -99,6 +99,8 @@ static uint8_t* g_workbuf; // Wuffs' workbuf.
static size_t g_workbuf_len;
static uint64_t g_num_configs;
static uint64_t g_num_short_checks;
static size_t g_short_workbuf_len; // 0 means use workbuf_len.
static size_t g_last_want_len;
static uint64_t g_num_mismatches;
@@ -116,6 +118,9 @@ typedef struct {
size_t metadata_len;
size_t dst_chunk; // 0 means unlimited.
uint64_t seed;
// try_short is whether to also check (at qualities 2 to 9) Wuffs' output
// with the shortest workbuf that should work: see short_workbuf_len.
bool try_short;
} config;
static void //
@@ -371,6 +376,9 @@ encode_wuffs(const config* c, size_t* have_len) {
goto cleanup;
}
}
if ((g_short_workbuf_len > 0) && (g_short_workbuf_len < wlen)) {
wlen = g_short_workbuf_len;
}
wuffs_base__slice_u8 workbuf =
wuffs_base__make_slice_u8(g_workbuf, (size_t)wlen);
@@ -492,6 +500,63 @@ describe(char* buf, size_t n, const char* name, const config* c) {
}
}
// short_workbuf_len returns the shortest workbuf (at qualities 2 to 9) that
// should work for the config c and an input of len bytes, given that
// workbuf_len is wlen, or 0 if it is not shorter than wlen. The ring buffer
// is the workbuf's last region, of (2 + (1 << rb_bits) + (1 << lgblock) + 7)
// bytes, and a shorter workbuf works if it holds (2 + len + 16) bytes of it
// and (len + 16) is at most (1 << rb_bits). This mirrors SanitizeParams,
// ComputeLgBlock and ComputeRbBits in quality.h.
static size_t //
short_workbuf_len(const config* c, size_t len, uint64_t wlen) {
int32_t quality = 11;
int32_t lgwin = 22;
int32_t lgblock = 0;
bool large_window = false;
for (size_t j = 0; j < c->num_params; j++) {
int32_t v = (int32_t)(c->values[j]);
switch (c->keys[j]) {
case 1:
quality = v;
break;
case 2:
lgwin = v;
break;
case 3:
lgblock = v;
break;
case 6:
large_window = v != 0;
break;
}
}
quality = (quality < 0) ? 0 : (quality > 11) ? 11 : quality;
if ((quality < 2) || (quality > 9)) {
return 0;
}
large_window = large_window && (quality > 2);
int32_t max_lgwin = large_window ? 30 : 24;
lgwin = (lgwin < 10) ? 10 : (lgwin > max_lgwin) ? max_lgwin : lgwin;
if (quality < 4) {
lgblock = 14;
} else if (lgblock == 0) {
lgblock = 16;
if ((quality >= 9) && (lgwin > lgblock)) {
lgblock = (lgwin < 18) ? lgwin : 18;
}
} else {
lgblock = (lgblock < 16) ? 16 : (lgblock > 24) ? 24 : lgblock;
}
int32_t rb_bits = 1 + ((lgwin > lgblock) ? lgwin : lgblock);
uint64_t rb_size = (uint64_t)1 << rb_bits;
uint64_t rb_region = 2 + rb_size + ((uint64_t)1 << lgblock) + 7;
if (((len + 16) > rb_size) || (rb_region > wlen)) {
return 0;
}
uint64_t n = wlen - rb_region + 2 + len + 16;
return (n < wlen) ? (size_t)n : 0;
}
static void //
check(const char* name, const config* c, const uint8_t* data, size_t len) {
char desc[512];
@@ -507,6 +572,41 @@ check(const char* name, const config* c, const uint8_t* data, size_t len) {
const char* have_err = encode_wuffs(c, &have_len);
const char* want_err = encode_mimic(c, &want_len);
g_last_want_len = want_len;
if (c->try_short && !have_err && !want_err) {
// Also check the shortest workbuf that should work, and that one byte
// less fails.
wuffs_brotli__encoder* enc = wuffs_brotli__encoder__alloc();
uint64_t wlen = 0;
if (enc) {
for (size_t j = 0; j < c->num_params; j++) {
wuffs_brotli__encoder__set_quirk(enc, brotli_enc_quirk_key(c->keys[j]),
c->values[j]);
}
wlen = wuffs_brotli__encoder__workbuf_len(enc).max_incl;
free(enc);
}
size_t short_len = short_workbuf_len(c, len, wlen);
if (short_len > 0) {
g_num_short_checks++;
g_short_workbuf_len = short_len - 1;
size_t too_short_len = 0;
const char* too_short_err = encode_wuffs(c, &too_short_len);
g_short_workbuf_len = short_len;
have_err = encode_wuffs(c, &have_len);
g_short_workbuf_len = 0;
if (!too_short_err ||
(too_short_err != wuffs_base__error__bad_workbuf_length)) {
g_num_mismatches++;
describe(desc, sizeof desc, name, c);
printf("MISMATCH %s: a workbuf of %zu bytes did not fail: %s\n",
desc, short_len - 1, too_short_err ? too_short_err : "ok");
fflush(stdout);
return;
} else if (have_err) {
have_err = "short workbuf failed";
}
}
}
if (have_err || want_err) {
g_num_mismatches++;
describe(desc, sizeof desc, name, c);
@@ -651,6 +751,7 @@ run_input_lw(const char* name, const uint8_t* data, size_t len, uint32_t q) {
c.chunking = ch;
c.flush = fl;
c.seed = 0x10000 | (w << 8) | (ch << 4) | fl | (q << 12);
c.try_short = true;
check(name, &c, data, len);
}
}
@@ -693,6 +794,7 @@ run_input_lw(const char* name, const uint8_t* data, size_t len, uint32_t q) {
c.chunking = 4;
c.flush = 2;
c.seed = 0x20000 | i | (w << 8) | (q << 12);
c.try_short = true;
check(name, &c, data, len);
}
}
@@ -872,6 +974,7 @@ run_input_far(const char* name, const uint8_t* data, size_t len) {
config c = make_config(q, lgwins[w]);
add_param(&c, 6, 1); // BROTLI_PARAM_LARGE_WINDOW.
c.seed = 0x40000 | (w << 8) | (q << 12);
c.try_short = true;
check(name, &c, data, len);
printf(" q=%u lgwin=%u: %zu compressed bytes\n", q, lgwins[w],
g_last_want_len);
@@ -1075,7 +1178,8 @@ main(int argc, char** argv) {
free(p);
}
printf("TOTAL: %" PRIu64 " configs, %" PRIu64 " mismatches\n", g_num_configs,
g_num_mismatches);
printf("TOTAL: %" PRIu64 " configs (%" PRIu64
" also with a short workbuf), %" PRIu64 " mismatches\n",
g_num_configs, g_num_short_checks, g_num_mismatches);
return g_num_mismatches ? 1 : 0;
}
+24 -1
View File
@@ -157,6 +157,12 @@ pub struct encoder? implements base.io_transformer(
rb_cur_size : base.u32,
rb_pos : base.u32,
// rb_short_workbuf is whether any transform_io call (at qualities 2
// to 9) had a workbuf shorter than workbuf_len. If so, the ring
// buffer's tail may be incomplete, so the input must stay short
// enough for the ring buffer never to wrap.
rb_short_workbuf : base.bool,
// The C code's BrotliDistanceParams fields (other than
// distance_postfix_bits and num_direct_distance_codes).
dist_alphabet_size_max : base.u32,
@@ -809,13 +815,20 @@ pub func encoder.transform_io?(dst: base.io_writer, src: base.io_reader, workbuf
var injected : base.bool
var copy_input_size : base.u64
var total : base.u64
this.ensure_initialized!()
if this.quality > 9 {
// TODO: implement Zopfli (qualities 10 and 11).
return "#unsupported encoder quality"
} else if (this.quality >= 2) and (args.workbuf.length() < this.workbuf_end) {
return base."#bad workbuf length"
// A workbuf shorter than workbuf_len works if it is long enough for
// the input so far (see the rb_short_workbuf check below), as long
// as the ring buffer never wraps.
this.rb_short_workbuf = true
if args.workbuf.length() < (this.rb_buf_off ~mod+ RB_SHORT_SLACK) {
return base."#bad workbuf length"
}
}
while true {
@@ -915,6 +928,16 @@ pub func encoder.transform_io?(dst: base.io_writer, src: base.io_reader, workbuf
if (remaining <> 0) and (args.src.length() > 0) {
copy_input_size = remaining.min(no_more_than: args.src.length())
if this.rb_short_workbuf {
// The ring buffer must not wrap (or reach its tail) and
// the workbuf must hold the input so far plus some
// slack.
total = (this.input_pos ~mod+ copy_input_size) ~mod+ RB_SHORT_SLACK
if (total > (this.rb_size as base.u64)) or
((this.rb_buf_off ~mod+ total) > args.workbuf.length()) {
return base."#bad workbuf length"
}
}
mark = args.src.mark()
args.src.skip?(n: copy_input_size)
this.copy_input_to_ring_buffer!(wb: args.workbuf, bytes: args.src.since(mark: mark))
+21 -14
View File
@@ -17,29 +17,36 @@
// The workbuf holds, in this order (see README.md's "Encoder Workbuf Layout"
// section, which compute_layout_offset mirrors):
// - the storage (the C code's GetBrotliStorage) for one metablock,
// - the ring buffer (the C code's RingBuffer.data_),
// - the hasher's memory (the C code's common->extra),
// - the commands (16 bytes each), and
// - the commands (16 bytes each),
// - at qualities 4 and above, the metablock split (see
// encode_metablock_greedy.wuffs), the literal context map, the
// EncodeContextMap symbols and the block encoders' depths and bits.
// EncodeContextMap symbols and the block encoders' depths and bits, and
// - the ring buffer (the C code's RingBuffer.data_).
// The workbuf layout's region indexes. LAYOUT_END's offset is the total
// length.
// The ring buffer is last, so that a workbuf shorter than workbuf_len works
// for short inputs (see transform_io's rb_short_workbuf check).
pri const LAYOUT_STORAGE : base.u32 = 0
pri const LAYOUT_RB : base.u32 = 1
pri const LAYOUT_HASH : base.u32 = 2
pri const LAYOUT_CMDS : base.u32 = 3
pri const LAYOUT_TYPES_0 : base.u32 = 4
pri const LAYOUT_LENGTHS_0 : base.u32 = 7
pri const LAYOUT_HISTO_0 : base.u32 = 10
pri const LAYOUT_COMB : base.u32 = 13
pri const LAYOUT_CMAP : base.u32 = 14
pri const LAYOUT_RLE : base.u32 = 15
pri const LAYOUT_BE_DEPTH_0 : base.u32 = 16
pri const LAYOUT_BE_BITS_0 : base.u32 = 19
pri const LAYOUT_HASH : base.u32 = 1
pri const LAYOUT_CMDS : base.u32 = 2
pri const LAYOUT_TYPES_0 : base.u32 = 3
pri const LAYOUT_LENGTHS_0 : base.u32 = 6
pri const LAYOUT_HISTO_0 : base.u32 = 9
pri const LAYOUT_COMB : base.u32 = 12
pri const LAYOUT_CMAP : base.u32 = 13
pri const LAYOUT_RLE : base.u32 = 14
pri const LAYOUT_BE_DEPTH_0 : base.u32 = 15
pri const LAYOUT_BE_BITS_0 : base.u32 = 18
pri const LAYOUT_RB : base.u32 = 21
pri const LAYOUT_END : base.u32 = 22
// RB_SHORT_SLACK is how many bytes past the input's end (in the ring buffer)
// a short workbuf must have: the C code reads at most 7 bytes past the
// input's end (its kSlackForEightByteHashingEverywhere), rounded up.
pri const RB_SHORT_SLACK : base.u64 = 16
// The C code's MAX_NUM_DELAYED_SYMBOLS (in quality.h).
pri const MAX_NUM_DELAYED_SYMBOLS : base.u64 = 0x2FFF
+54 -1
View File
@@ -1331,7 +1331,7 @@ test_wuffs_brotli_encode_parameters() {
dst.meta.wi = 0;
status = wuffs_brotli__encoder__transform_io(
enc, &dst, &src,
wuffs_base__make_slice_u8(g_work_slice_u8.ptr, (size_t)(wlen - 1)));
wuffs_base__make_slice_u8(g_work_slice_u8.ptr, (size_t)(wlen / 2)));
BROTLI_ENC_CHECK(status.repr == wuffs_base__error__bad_workbuf_length,
"short workbuf at quality 2..9");
}
@@ -1373,6 +1373,59 @@ test_wuffs_brotli_encode_parameters() {
}
}
// At qualities 2 to 9, the ring buffer is the workbuf's last region (of
// (2 + (1 << rb_bits) + (1 << lgblock) + 7) bytes) and a shorter workbuf
// works if it holds (2 + input_length + 16) bytes of it (and the input is
// short enough for the ring buffer never to wrap).
{
free(enc);
enc = wuffs_brotli__encoder__alloc();
if (!enc) {
RETURN_FAIL("alloc failed");
}
wuffs_brotli__encoder__set_quirk(enc, WUFFS_BROTLI__QUIRK_ENCODER_QUALITY,
3);
wuffs_brotli__encoder__set_quirk(enc, WUFFS_BROTLI__QUIRK_LGWIN, 30);
wuffs_brotli__encoder__set_quirk(enc, WUFFS_BROTLI__QUIRK_LARGE_WINDOW, 1);
uint64_t wlen = wuffs_brotli__encoder__workbuf_len(enc).max_incl;
uint64_t rb_region = 2 + (2ull << 30) + (1 << 14) + 7;
BROTLI_ENC_CHECK(wlen > rb_region, "workbuf_len at q3w30");
size_t short_len = (size_t)(wlen - rb_region + 2 + 3 + 16);
uint8_t* short_workbuf = malloc(short_len);
if (!short_workbuf) {
RETURN_FAIL("malloc failed");
}
for (int k = 0; k < 2; k++) {
wuffs_brotli__encoder* e = wuffs_brotli__encoder__alloc();
if (!e) {
free(short_workbuf);
RETURN_FAIL("alloc failed");
}
wuffs_brotli__encoder__set_quirk(e, WUFFS_BROTLI__QUIRK_ENCODER_QUALITY,
3);
wuffs_brotli__encoder__set_quirk(e, WUFFS_BROTLI__QUIRK_LGWIN, 30);
wuffs_brotli__encoder__set_quirk(e, WUFFS_BROTLI__QUIRK_LARGE_WINDOW,
1);
wuffs_base__io_buffer s = make_io_buffer_from_string("abc", 3);
s.meta.closed = true;
dst.meta.wi = 0;
status = wuffs_brotli__encoder__transform_io(
e, &dst, &s,
wuffs_base__make_slice_u8(short_workbuf, short_len - (k ? 0 : 1)));
free(e);
if (k == 0) {
if (status.repr != wuffs_base__error__bad_workbuf_length) {
free(short_workbuf);
RETURN_FAIL("too short workbuf at q3w30: %s", status.repr);
}
} else if (status.repr) {
free(short_workbuf);
RETURN_FAIL("short workbuf at q3w30: %s", status.repr);
}
}
free(short_workbuf);
}
// Qualities 10 and 11 (and 12, which sanitizes to 11) are unsupported.
for (uint32_t q = 10; q <= 12; q++) {
free(enc);