zlib: Brotli reset() drops quality and dictionary
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 76/100
- Issue-Typ
- Bug
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- cpp, javascript, node.js
Rechercherichtung
Start in src/node_zlib.cc at BrotliEncoderContext::ResetStream, BrotliDecoderContext::ResetStream, and Init(), then run the JavaScript reproduction from the issue. Verify that reset preserves Brotli quality parameters and dictionaries for compression and decompression, and add regression coverage showing the configured behavior remains after reset.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Version
v27.0.0-pre (built from main at a2a051cd42; src/node_zlib.cc is unchanged on current main)
Platform
Linux x86_64 (Ubuntu 22.04, built with clang 20)
Subsystem
zlib
What steps will reproduce the bug?
Create a Brotli compressor with a custom quality or a dictionary, call .reset() before writing anything, then compress as usual.
The quality/dictionary you passed in is gone. Nothing throws.
import * as zlib from 'node:zlib';
const input = Buffer.from('the quick brown fox jumps over the lazy dog '.repeat(100));
const dict = Buffer.from('the quick brown fox jumps over the lazy dog '.repeat(40));
function compress(options, reset) {
return new Promise((resolve, reject) => {
const s = zlib.createBrotliCompress(options);
const chunks = [];
s.on('data', (d) => chunks.push(d));
s.on('error', reject);
if (reset) s.reset();
s.end(input);
s.on('end', () => resolve(Buffer.concat(chunks).length));
});
}
const q0 = { params: { [zlib.constants.BROTLI_PARAM_QUALITY]: 0 } };
console.log('quality 0, no reset:', await compress(q0, false)); // 109
console.log('quality 0, then reset:', await compress(q0, true)); // 55 (same as default quality 11)
console.log('with dictionary, no reset:', await compress({ dictionary: dict }, false)); // 18
console.log('with dictionary, then reset:', await compress({ dictionary: dict }, true)); // 55 (same as no dictionary)
const compressed = zlib.brotliCompressSync(input, { dictionary: dict });
const dec = zlib.createBrotliDecompress({ dictionary: dict });
dec.reset();
dec.end(compressed);
dec.on('error', (err) => console.log('decompress after reset:', err.code));
// ERR__ERROR_FORMAT_DICTIONARY
How often does it reproduce? Is there a required condition?
Always. You do not need to write any data first. Just construct the stream with options and call reset().
What is the expected behavior? Why is that the expected behavior?
reset() should start a new Brotli session on the same stream, keeping the quality/params and dictionary you already set.
That is what the same API already documents for Zstd (zlib.reset(): "start a new session while preserving the configured parameters and dictionary"), and it is what test/parallel/test-zlib-zstd-reset.js asserts. Brotli goes through the same JS reset() method.
If the dictionary is dropped, a decoder cannot read a dictionary-compressed frame at all.
What do you see instead?
- Quality 0 after
reset()compresses as if you had used the default quality 11 (109 bytes become 55). - A dictionary after
reset()compresses as if you had used no dictionary (18 bytes become 55). createBrotliDecompress({ dictionary })thenreset()fails withERR__ERROR_FORMAT_DICTIONARYon a frame that was compressed with that dictionary.
The compressor never reports an error. The settings just disappear.
Additional information
C++: BrotliEncoderContext::ResetStream / BrotliDecoderContext::ResetStream both do return Init(); with no arguments. Init() immediately does dictionary_.clear() and creates a brand-new Brotli instance. It never replays SetParams.
This is not #66087 / #66088. Those are about flush() then reset() leaving a broken frame. Here there is no write at all — only the configuration is thrown away.
LLDB on src/node_zlib.cc at a2a051cd42 (same ResetStream/Init as current main):
- Stopped in
BrotliEncoderContext::ResetStreamat line 1514. Watch:this->dictionary_still has size 1760. Next statement isreturn Init();with no dictionary argument.
- That call lands in
Initat line 1474, ondictionary_.clear();. Watch: the memberthis->dictionary_is still 1760 (clear has not run yet), but thedictionaryparameter is already size 0, becauseResetStreamdid not pass it in.
- Continue to line 1483,
if (!dictionary.empty()). Watch: boththis->dictionary_and thedictionaryparameter are now size 0, so the attach-dictionary branch is skipped.
- Vorherrschende Sprache
- JavaScript
- Sterne
- 122k
- Forks
- 38.4k
- Ø Merge
- 3 T. 22 Std.
- Gemergte PRs (30 T.)
- 273
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus nodejs/node
-
build / doc: missing platform and toolchain info for `linux-x64-musl`Evtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. Offenalpine build doc
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
Maintainer antworten meist innerhalb von 1 Tag
-
[Docs] `process.loadEnvFile()` does not document behaviour when variables already existEvtl. vergeben @Sepandard hat das vor 10 Tagen übernommen. Offendoc
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 90/100
Maintainer antworten meist innerhalb von 1 Tag
-
Stream.prototype.forEach will block in first promise in queue before read more chunkEvtl. vergeben @mmustafasenoglu hat das vor 10 Tagen übernommen. Offendoc
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
Maintainer antworten meist innerhalb von 1 Tag
-
build
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 88/100
nodejs/node#66076 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
`TextEncoder.encodeInto()` underfills the destination for some non-ASCII textEvtl. vergeben @XadillaX hat das vor 24 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
nodejs/node#65994 · 2 Kommentare · 2 Reaktionen ·
Maintainer antworten meist innerhalb von 1 Tag
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 80/100
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
NationalSecurityAgency/skills-service#4052 ·
Maintainer antworten meist innerhalb von 1 Tag
-
documentation
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 88/100
githubnext/gh-aw-workshop#4251 ·
Maintainer antworten meist innerhalb von 1 Tag
-
customer-support needs-triage Platform(Default)
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
Maintainer antworten meist innerhalb von 2 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Leonxlnx/taste-skill#129 ·
Maintainer antworten meist innerhalb von 1 Tag