Will Woods
banner
wizard.zone
Will Woods
@wizard.zone
Software Engineer, former Red Hatter. This is where I holler into the void about packaging systems & Rust & software supply-chain security &c.

Shitposting: @willrad.bsky.social
GitHub: https://github.com/wgwoods

The mustard (still) indicates progress 🌭
Fixed it! Part of me thinks I should try to make a minimal reproducer, just because.. wow, that was a weird one.

OTOH I don't know if there's a lesson here other than "my code was stupid and ugly, and x86_64 & arm64 have slightly different memory ordering". I already know these things!
March 13, 2025 at 2:21 AM
no harm done! was a fun adventure!

buffers just love overflowing so dang much
March 1, 2025 at 5:16 AM
ah shit I forgot there's no money in fixing problems!!
March 1, 2025 at 2:31 AM
YEEHAW MISSION ACCOMPLISHED, I'M TECHNICALLY ALMOST A RUST CONTRIBUTOR

TIME TO BECOME CRAB BABYYYYY 🦀🦀🦀
March 1, 2025 at 2:21 AM
Aaaand fixing the suspicious code in Buffer::read_more() fixes the crash. Success!!

Here's the PR to get the fix upstream: github.com/rust-lang/ru...
Fix crash in BufReader::peek() by wgwoods · Pull Request #137832 · rust-lang/rust
bufreader_peek tracking issue: #128405 This fixes a logic error in Buffer::read_more() that would make BufReader::peek() expose uninitialized data and/or segfault if read_more() was called with a p...
github.com
March 1, 2025 at 2:21 AM
Changed it to peek(5) after the read(4) - which should trigger a read_more() while there's still data in the buffer - and blammo:

---- library/std/src/io/buffered/bufreader.rs - io::buffered::bufreader::BufReader<R>::peek (line 117) stdout ----
Test executable failed (signal: 6 (SIGABRT)).
March 1, 2025 at 1:23 AM
6. read_to_string(s) - reads everything left ("hello") into s. Reader is now at EOF.
7. peek(1) - calls read_more(), but reader is at EOF, so it returns 0 and returns an empty buffer.

So the test does call read_more().. but it never actually reads anything! So let's fix that!
March 1, 2025 at 1:08 AM
What the doctest does:
1. Make a Reader (`bytes`) containing 9 bytes: "oh, hello"
2. Wrap it in a BufReader (`buf`) with a 6-byte capacity
3. peek(2) - this causes a buffer fill. buf contains "oh, he". 4. read 4 bytes: "oh, ". buf now contains "he".
5. peek(2) - just returns "he". (cont'd..)
March 1, 2025 at 1:08 AM
Anyway! `/x.py test library/std` takes a while but all the tests pass. Great work Rust folks, high-fives all around, &c.

Now let's see if I can trigger the problem. Let's look at BufReader::peek() and its doctest: github.com/rust-lang/ru...
March 1, 2025 at 1:08 AM
Have I mentioned that my internet connection is a point-to-point microwave wireless link that we share with our neighbor 'cuz our house doesn't have line-of-sight to the tower?

SORRY ABOUT YOUR NETFLIX STREAMING QUALITY BUT I GOTTA REINSTALL XCODE BECAUSE NOBODY KNOWS HOW TO FIX CONFIG FILES
March 1, 2025 at 12:23 AM
apparently the only suggestion for this is.. delete & reinstall the xcode commandline utils?

sudo rm -rf $(xcode-select -p) && xcode-select --install

[redownloads 2GB of data I already had]

...aaaaand now it works! What a cool and efficient way to fix my tooling configuration!!
March 1, 2025 at 12:10 AM
Okay fine whatever, setup complete, let's see if we can build the libraries! And.. uh.. hm.

fatal error: 'iostream' file not found

hoorayyyyyyy missing search paths, my favorite
March 1, 2025 at 12:02 AM
So first I guess I'll clone the rust-lang/rust repo. Yeehaw, 670MG of data, let's go!

Next they suggest using their `x.py` tool to bootstrap the build environment.

Is this gonna download a buncha binary tarballs from rust-lang.org without checking sigs or certs? HELL YEAH, I LOVE SOFTWARE
March 1, 2025 at 12:02 AM
First, the bug: I think there's a logic error in std::io::buffered::Buffer::read_more() that will make std::io::BufReader::peek() segfault if it has to refill the buffer.

I'm not using peek() - or nightly, for that matter - but I *did* steal Buffer::read_more() for my own thingy.
March 1, 2025 at 12:02 AM