Blog

The Loop That Trusted Itself: How One German Letter Exposed a Ten-Year-Old Flaw in Ruby

2026-11-20

A German letter that expands from one character to two exposed a ten-year-old buffer-write flaw in Ruby, and a broader lesson about unwritten assumptions in infrastructure code.

The Loop That Trusted Itself

A recently disclosed security issue in Ruby reads like a textbook lesson on writing beyond an allocated buffer. The case is instructive well beyond the Ruby community, because the flaw sits in the kind of foundational infrastructure code that much of the network runs on.

What the code does

The affected code lives in the ISO-8859-1 encoding file of the Ruby source (enc/iso_8859_1.c). A loop walks over an input buffer and writes an uppercase version of it into an output buffer. Two pointers define the boundaries: end marks the end of the input, and to_end marks the end of the output buffer.

In each iteration the loop takes the next input character into a variable and checks for special characters. The first special character it checks is where the flaw lives.

Where the assumption broke

That character is the German ß. When it is converted to uppercase, the correct result is two characters: SS.

The loop's basic guard is the check that the output pointer is still below the end of the output buffer. That check implicitly assumes that every input character produces exactly one output character. Once a single input character can produce two, the guard has to verify that an extra byte of room remains. It did not, and the loop could write past the end of the buffer.

The corrected version changes the loop condition so that it requires more than one free byte in the output buffer: to_end - to > 1.

The detail that makes this interesting

The original loop and the ß condition were written in the same commit by the same developer. This is not a regression in which someone later added a condition and forgot to update the loop. One person wrote both the ß handling and the space check, and missed the interaction between them: the write that lands after the end of the buffer.

It took ten years for the bug to be discovered.

The lesson for engineering and security leaders

Three points stand out.

First, invariants fail at the edges. The rule held for the common case and was silently false for the special one. The guard never learned about the exception.

Second, author review is structurally weak. The developer who writes both halves carries the same assumption into the review of both halves. Independent, systematic reading is the control that catches this.

Third, this is exactly the class of problem developers have tried to eliminate for decades, and where AI coding agents may finally help. AI systems have their own security problems, but as systematic readers of foundational infrastructure code, they represent a significant leap.

The bottom line

The most dangerous defects are rarely buried in complexity. They sit inside assumptions nobody wrote down. For organizations that depend on open-source infrastructure, in government, defense and critical industry alike, the practical question is simple: which of your core components rely on an assumption that only its author has ever examined?