News for hackers. Stuff that matters.
Re:Zig's Curious Multi-Sequence for Loops by krona on Monday February 27, 2023 @10:27AM (#34957470)
Without bounds checks: game crashes, core dump.

With bounds checks: game crashes, meaningless error message given to the user.

What am I missing?

Re:Zig's Curious Multi-Sequence for Loops by ekimekim on Monday February 27, 2023 @10:35AM (#34957596)
With bounds checks: game crashes, meaningless error message given to the user.

Without bounds checks: I join a multiplayer lobby, and the next thing I know my computer is part of a botnet.

This isn't an imaginary fear, it has happened many times. Some examples from a brief search: https://gridinsoft.com/blogs/rce-vulnerability-in-gta-online... https://www.polygon.com/22898895/dark-souls-pvp-exploit-mult... https://security.gerhardt.link/RCE-in-Factorio/

I am not claiming all of these would've been prevented by bounds checking arrays, or even memory safety in general. The point is that security is not optional just because it's a game.

Re:Zig's Curious Multi-Sequence for Loops by dxhdr on Monday February 27, 2023 @11:34AM (#34958434)
Now suppose your game runs in a WASM sandbox and re-run those scenarios. What do you gain from bounds checks?

I'm not suggesting that shipping without bounds checks is wise or leads to a better product. However I do think with /some games/ security is basically not a concern.

Re:Zig's Curious Multi-Sequence for Loops by Arnavion on Monday February 27, 2023 @12:46PM (#34959510)
Heartbleed still happens inside a sandbox, because it's the sandboxed memory that leaks. For multiplayer games specifically, that can be a client auth key that can be used to impersonate you.
Re:Zig's Curious Multi-Sequence for Loops by titzer on Monday February 27, 2023 @10:39AM (#34957661)
> Without bounds checks: game crashes, core dump.

I think it's more like (assuming it does actually go out of bounds at some point):

30% chance of core dump right away

20% chance of core dump at some point after errant write

40% chance it never crashes in testing

5% chance it doesn't crash the first year after shipping

5% chance it never crashes

With an explicit bounds check, all of these scenarios result in a crash at the exact location where the program first violated safety[1]. The developer gets a source-level crash and doesn't spend the first 20 minutes just trying to figure out what the crash dump even means.

[1] Hopefully with a complete stacktrace, maybe even the index and length values!

It's time we recognized that all our tooling should be designed to help us programmers who do have bugs in our program. Like, this crashing part is the normal part that all the tools should help deal with.

Re:Zig's Curious Multi-Sequence for Loops by nordsieck on Monday February 27, 2023 @10:30AM (#34957533)
> What am I missing?

Sometimes without bounds checking you get an exploit instead of a crash.

Re:Zig's Curious Multi-Sequence for Loops by gaganyaan on Monday February 27, 2023 @10:34AM (#34957592)
The meaningless error message can be entered into Google and the user can find a thread about how to fix their specific problem instead of wading through endless threads of similar-but-unrelated problems.
Re:Zig's Curious Multi-Sequence for Loops by adgjlsfhk1 on Monday February 27, 2023 @01:15PM (#34959922)
the bounds check can sometimes catch the error before it corrupts your save.