Bug 24458 – Mac M3 associative array keys on std.net.curl gets overwritten

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
Other
OS
Mac OS X
Creation time
2024-03-27T16:21:45Z
Last change time
2024-03-31T19:39:41Z
Keywords
pull
Assigned to
No Owner
Creator
Marcelo Silva Nascimento Mancini
See also
https://issues.dlang.org/show_bug.cgi?id=2954

Comments

Comment #0 by msnmancini — 2024-03-27T16:21:45Z
```d import std; void main() { auto conn = HTTP(); conn.url = "https://github.com/ldc-developers/ldc/releases/download/v1.36.0-beta1/ldc2-1.36.0-beta1-osx-universal.tar.xz"; conn.onReceive = (ubyte[] data) { writeln(conn.responseHeaders); return data.length; }; conn.perform(); } ``` This issue only happened through Mac M3 until now.
Comment #1 by msnmancini — 2024-03-27T16:27:25Z
I got that printed btw: ``` ["\r\n\0tent":"S1711554434.755792,VS0,VE506", "\r\n\0t":"\"0x8DBF529351DA33D\"", "\r\n\0tent-length: 15":"Tue, 05 Dec 2023 00:29:13 GMT", "\r\n\0tent-len":"cache-iad-kcgs7200155-IAD, cache-gru-sbgr1930059-GRU", "\r\n\0tent-leng":"0, 0", "\r\n\0tent-length: ":"available", "\r\n\0tent-leng":"2020-10-02", "\r\n\0tent-length":"BlockBlob", "\r\n\0tent-length:":"38677530-b01e-004d-515d-802eb9000000", "\r\n\0":"1.1 varnish, 1.1 varnish", "\r\n\0tent-len":"PmPmV2w5qfhV/9imSY2qNg==", "\r\n\0tent":"MISS, HIT", "\r\n\0tent-length: 150":"attachment; filename=ldc2-1.36.0-beta1-osx-universal.tar.xz", "\r\n\0t":"Wed, 27 Mar 2024 15:47:14 GMT", "\r\n\0ten":"Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", "\r\n\0tent-length":"150538836", "\r\n\0tent-length: 1":"unlocked", "\r\n\0":"384", "\r\n\0tent-lengt":"bytes", "\r\n\0tent-length: 15053":"true", "\r\n\0tent-lengt":"Tue, 05 Dec 2023 00:29:13 GMT", "\r\n\0tent-leng":"application/octet-stream"] ```
Comment #2 by schveiguy — 2024-03-27T16:35:00Z
Note that the root cause here is the use of `toLower` on the header key. Since `toLower` will avoid allocating a new array if the input is already lower case, the slice of the original curl buffer is returned (if e.g. it's `content-type` instead of `Content-type`). This means you store a slice to a reusable buffer from curl as the string key. For the reason why this is allowed, when `const(char)[]` does not convert to `string`, see issue 2954.
Comment #3 by dlang-bot — 2024-03-27T16:59:50Z
@MrcSnm updated dlang/phobos pull request #8961 "Fix Issue 24458 - Mac M3 associative array keys on std.net.curl gets overwritten" fixing this issue: - Fix Bugzilla Issue 24458 - Mac M3 associative array keys on std.net.curl gets overwritten https://github.com/dlang/phobos/pull/8961
Comment #4 by dlang-bot — 2024-03-31T19:39:41Z
dlang/phobos pull request #8961 "Fix Bugzilla Issue 24458 - Mac M3 associative array keys on std.net.curl gets overwritten" was merged into stable: - afb0b3485b918e97caff0476f2e60e1d936aafeb by MrcSnm: Fix Bugzilla Issue 24458 - Mac M3 associative array keys on std.net.curl gets overwritten - 4d332baad1a053d8aa67ff3cff80f7787182cbe7 by MrcSnm: Fix Bugzilla Issue 24458 - Mac M3 associative array keys on std.net.curl gets overwritten https://github.com/dlang/phobos/pull/8961