Menu

1 / 5

21 ß's, 1 byte: Ruby's upcase overflows its own buffer

DEV Community: rails·frank chu·11 days ago
#l7tkM0Bf
#devtorails#devto#dev#ruby#byte
Long article (934 words) — no AI summary yet.
Reading 0:00
15s threshold

21 ß's, 1 byte: Ruby's upcase overflows its own buffer

21 characters of input. 1 byte past the end of the buffer. That is the entire vulnerability: Ruby's upcase has been overflowing a heap buffer since version 2.4.0 — eight years — and it took a single character, ß , to do it. Veria Labs disclosed it on November 18 as Ruby2Shell (GHSA-34m4-m9fh-gqp5), pre-authentication remote code execution on stock Rails.

The root cause is a bounds check that counts bytes in the wrong unit. Most of Ruby's single-byte encodings have no capital ß . Upcasing it produces two bytes, SS , but the conversion loop only bounds-checks for one. Here is the loop, quoted from the write-up:

while ( * pp < end && to < to_end ) { /* room for one byte */ code = * ( * pp ) ++ ; if ( code == SHARP_s ) { if ( flags & ONIGENC_CASE_UPCASE ) { * to ++ = 'S' ; /* first byte */ code = 'S' ; } /* ... */ } /* ...…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.