Bug 24165 – Failed readf leaves File in inconsistent state

Status
NEW
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2023-09-26T17:29:23Z
Last change time
2024-12-01T16:41:52Z
Keywords
pull
Assigned to
No Owner
Creator
Paul Backus
Moved to GitHub: phobos#10533 →

Comments

Comment #0 by snarwin+bugzilla — 2023-09-26T17:29:23Z
Example: --- $ echo "-hello" > input $ cat example.d import std.stdio, std.format, std.algorithm; void main() { auto f = File("input"); int n; try f.readf("%d", n); catch (Exception e) {} f.byChunk(1).copy(stdout.lockingBinaryWriter); } $ dmd -run example.d hhello --- After the failed call to File.readf, subsequent reads from `f` result in corrupted data.
Comment #1 by dlang-bot — 2023-10-14T23:49:27Z
@pbackus created dlang/phobos pull request #8826 "Fix Issue 24165 - Failed readf leaves File in inconsistent state" fixing this issue: - Fix Issue 24165 - Failed readf leaves File in inconsistent state Previously, a failed call to readf resulted in multiple copies of the same LockingTextWriter being destroyed. Since LockingTextWriter's destructor calls ungetc on the last-read character, this caused that character to appear multiple times in subsequent reads from the File. This change ensures that the destructor in question is only run once by making LockingTextWriter a reference-counted type. Ideally, to avoid unnecessary overhead, this issue would have been fixed by making LockingTextWriter non-copyable. However, non-copyable ranges are poorly-supported by Phobos, and this approach would have required extensive changes to several other modules, including changes to the interfaces of some public symbols. https://github.com/dlang/phobos/pull/8826
Comment #2 by robert.schadek — 2024-12-01T16:41:52Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/10533 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB