News for hackers. Stuff that matters.
Re:Glibc Buffer Overflow in Iconv by tialaramex on Sunday April 21, 2024 @11:55AM (#40106716)
Huh. Where is the "indirect promise" ? Is there a (conventionally hinted as "free", so it's not good if there's one which isn't very cheap) as function? Like as_os_string or something?
Re:Glibc Buffer Overflow in Iconv by LegionMammal978 on Sunday April 21, 2024 @01:44PM (#40107613)
It's because str implements AsRef<OsStr> [0]. The function signature promises that whenever you have a borrowed &'a str, the standard library can give you a borrowed &'a OsStr with the same data.

Since references can't have destructors (they don't own the data like an OsString does), it means that the standard library can't give you a newly-allocated string without leaking it. Since obviously it isn't going to do that, the &OsStr must instead just act as a view into the underlying &str. And the conversion can't enforce any extra restrictions on the input string without breaking backward compatibility.

The overall effect is that whatever format OsStr uses, it has to be a superset of UTF-8.

[0] https://doc.rust-lang.org/1.77.2/std/ffi/struct.OsStr.html#i...

Re:Glibc Buffer Overflow in Iconv by tialaramex on Sunday April 21, 2024 @03:27PM (#40108468)
Ah, an AsRef<OsStr>, yep that would do it. Thanks.