Bug 18773 – Constraints on buffer re-use for std.zlib should be documented.

Status
NEW
Severity
enhancement
Priority
P4
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-04-17T20:32:19Z
Last change time
2024-12-01T16:33:29Z
Keywords
bootcamp
Assigned to
No Owner
Creator
briancschott
Moved to GitHub: phobos#9755 →

Comments

Comment #0 by briancschott — 2018-04-17T20:32:19Z
The Compress and UnCompress classes have undocumented restrictions on when the buffers passed to their `compress` and `uncompress` methods can be re-used. This needs to be fixed so that people are not accidentally creating or reading corrupted data.
Comment #1 by zan77137 — 2020-09-15T11:49:46Z
This issue seems to be implementation problems rather than undocumented restrictions: since the argument of compress/uncompress is requiring const(void)[], the function has to take into account the possibility that the buffer may be changed. Specifically, the following code does not work: ----------------------------------------------- auto compressed = appender!(ubyte[])(); scope compress = new Compress(HeaderFormat.gzip); char[128] buffer; foreach (e; ["abc", "abcdefghijk"]) { auto line = sformat!"%s\n"(buffer, e); // Invalid buffer is held by Compress const compressedLine = compress.compress(line); compressed.put(cast(const(ubyte)[]) compressedLine); } compressed.put(cast(const(ubyte)[]) compress.flush()); ----------------------------------------------- To solve this, there are two policies: 1. Change the type of argument to immutable(void)[] (this is a breaking change) 2. Copy the argument's buffer, and manage the life of the copied buffer in Compress/UnCompress.
Comment #2 by robert.schadek — 2024-12-01T16:33:29Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/9755 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB