You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Result[str, E].unwrap_or returns a str with the payload's length and a bad data pointer (segfault / garbage) #1363
Result[str, E].unwrap_or(default) yields a str whose length is the Ok payload's but whose bytes are not: reading it faults or returns garbage.
Spec: §10 (Option/Result eliminators) and D22 (unwrap_or is a contextual join; the result must be the payload or the default, never a mix).
Repro (a stage1 built from origin/main 5fd93bc; the installed v0.15.2.1 behaves the same):
use std.fs
fn main:
let r = read_file("/tmp/p70k.txt") // any file of ~70 KB (a 92-byte file prints garbage instead of faulting)
let t = r.unwrap_or("")
print(t.slice(0, 8))
Actual: SIGSEGV. lldb:
stop reason = EXC_BAD_ACCESS (code=1, address=0x100098010)
frame #0 rt_memcpy at rt_core.w:324:18 [inlined]
frame #1 alloc_str at rt_core.w:1643:25
frame #2 main at repro.w:5:22
t.len() prints the file's length (399682 for src/Parser.w); t.slice(...) / .replace(...) / print(t) read from a bad data pointer. With a 92-byte file the same program prints a line of spaces. match read_file(p): Ok(t) => ... works, so the defect is in the unwrap_or path (MirLower lower_unwrap_or_method, src/MirLower.w ~12485, or the D22 join feeding it).
Expected: t is the file's text.
Workaround used: match read_file(p): Ok(t) => t, Err(_) => "".
Found while building the #1354 matrix: with run of a one-off rewrite script that did read_file(path).unwrap_or("") on src/Parser.w segfaulted.
Activity
debug allocator: a second free of a str buffer is a DOUBLE FREE, not …
MirLower: unwrap_or / unwrap_or_else / flatten retire the subject the…
MirLower: a user carrier's `?` retires branch()'s ControlFlow temp — …
debug allocator: a second free of a str buffer is a DOUBLE FREE, not …
MirLower: unwrap_or / unwrap_or_else / flatten retire the subject the…
MirLower: a user carrier's `?` retires branch()'s ControlFlow temp — …
Option.filter's predicate observes `&T`; filter / inspect / context r…
Sema: a lazy fallback returning a bare generic (`(_) => Vec.new()`) r…
validate-ownership: a drop that frees a sub-place moved out without a…
MirLower: a move out of a variant payload is reset-on-move; a failed …
Sema: a lazy fallback returning a bare generic (`(_) => Vec.new()`) r…
validate-ownership: a drop that frees a sub-place moved out without a…
MirLower: a move out of a variant payload is reset-on-move; a failed …
Restore Vec.clone in drop-state storage; pin the cross-unit receiver …
Sema: a lazy fallback returning a bare generic (`(_) => Vec.new()`) r…
validate-ownership: a drop that frees a sub-place moved out without a…
MirLower: a move out of a variant payload is reset-on-move; a failed …
validate-ownership: a drop that frees a sub-place moved out without a…
MirLower: a move out of a variant payload is reset-on-move; a failed …
validate-ownership rejects vacated payloads and moves through referen…
unwrap_or / unwrap_or_else / flatten no longer free the payload they …