If I had more time I'd write up something about this (maybe will still), but this PR is a good example of why explicit error sets in Zig and explicit checked math is important: github.com/ghostty-org/ghostty

The gist of it is we had implicit error sets in our terminal resize code path along with poor errdefer that allowed for errors we should've handled to cause memory corruption and integer overflows.

These overflows would lead to Ghostty allocating 4GB pages (lots of them) very quickly. You'd see Ghostty go from normal memory to literally hundreds of GB in a second (if your system can handle it via swap). This was a SUPER RARE issue but one we did see happen to users a couple times. It was very hard to trigger with normal workloads.

These were two separate issues that played together to cause this. This bug has existed since our public release and into the private beta.

The fix was to fix up some integral types, do checked math on this path even in unsafe builds, and to use explicit error sets such that our resize path can now only fail on true system OOM.

We also fixed up our errdefer handling to not produce the correct result, but at least produce a coherent result so its not corrupting anything.

This is an important fix.

0

If you have a fediverse account, you can quote this note from your own instance. Search https://hachyderm.io/users/mitchellh/statuses/115907459782038262 on your instance and quote it. (Note that quoting is not supported in Mastodon.)