Bug 20778 – exception messages with nulls within are treated inconsistently
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-04-28T01:44:12Z
Last change time
2022-04-04T21:43:17Z
Keywords
pull
Assigned to
No Owner
Creator
elpenguino+D
Comments
Comment #0 by elpenguino+D — 2020-04-28T01:44:12Z
```
throw new Exception("hello\0world!");
```
As of DMD 2.091.1, the printed message is inconsistent between platforms. On windows, the full string is printed. on other platforms, only "hello" is printed.
I would expect the entire string to be printed in all cases, but it seems some code in druntime expects the latter case instead (see core.internal.array.casting.onArrayCastError, for example).
This inconsistency appears to have been introduced between 2.064 and 2.065, when the default exception printer was changed from using write() to fprintf() on non-windows platforms.
Comment #1 by dlang-bot — 2022-03-24T16:25:11Z
@MoonlightSentinel updated dlang/druntime pull request #3787 "Fix 20778 - Ensure that _d_print_throwable prints the entire message" fixing this issue:
- Fix 20778 - Ensure that _d_print_throwable prints the entire message
The previous implementation simply forwarded the pointer + length to
`fprintf` and didn't check the return value. This caused the message to
be truncated for the following cases:
- it contains `\0` (the bug report)
- the length is greater than `int.max`
This commit changes the implementation s.t. it checks the character
count written to `stderr` (the return value) and prints the remainder
of the string if necessary.
https://github.com/dlang/druntime/pull/3787
Comment #2 by dlang-bot — 2022-04-01T11:02:25Z
dlang/druntime pull request #3793 "merge stable" was merged into master:
- 84e429a7c7c99ebae6e72de2f2be3069266394a5 by MoonlightSentinel:
Fix 20778 - Ensure that _d_print_throwable prints the entire message
The previous implementation simply forwarded the pointer + length to
`fprintf` and didn't check the return value. This caused the message to
be truncated for the following cases:
- it contains `\0` (the bug report)
- the length is greater than `int.max`
This commit changes the implementation s.t. it uses `fwrite` instead
which doesn't stop at `\0` and (theoretically) supports lengths up to
`size_t.max`
- 13441f120f669571c5941c5cef3196e7fd9d3a95 by Razvan Nitu:
Merge pull request #3787 from MoonlightSentinel/truncated-exception-message
Fix 20778 - Ensure that _d_print_throwable prints the entire message
https://github.com/dlang/druntime/pull/3793
Comment #3 by kdevel — 2022-04-04T21:43:17Z
*** Issue 21480 has been marked as a duplicate of this issue. ***