CVE-2026-132825: One Sharp S Too Many -- A One-Byte Heap Overflow in Ruby's Case Conversion
The advisory
On 2026-11-18 the Ruby team published a security advisory for seven vulnerabilities in the regular expression engine and in the case conversion of strings, and released Ruby 3.3.14, 3.4.13 and 4.0.10 to fix them. One of the seven is GHSA-34m4-m9fh-gqp5, now CVE-2026-132825, rated CVSS 7.4. You may have seen it under the name Ruby2Shell. The advisory gives it three sentences: Ruby has a one-byte heap-based buffer overflow in the case conversion of strings, changing the case of a crafted string “may allow remote code execution”, and the Ruby team is aware of PoCs that reach it in some scenarios. It affects every Ruby up to 3.3.13, 3.4.0 through 3.4.12 and 4.0.0 through 4.0.9. It does not say which string, which method or which encoding, and when I checked on 2026-11-19 no public PoC code existed.
So I set out to find the string, starting from the fix commit. It turned out to be 21 bytes long. One HTTP request with no credentials, carrying 21 copies of the byte 0xDF and a Content-Type that declares ISO-8859-1, makes Ruby 3.4.12 write one byte past the end of a heap buffer inside a Sinatra application. The proof is the target’s own AddressSanitizer report, the same request is answered correctly by Ruby 3.4.13, and the run is in a live pcap.
That is a lower impact than the advisory describes, and I want to be plain about it from the first screen. I did not reach remote code execution against the product. But a separate in-process harness on the same vulnerable build (stock, no sanitizer, glibc 2.41) triggers the real String#downcase(:fold) overflow on a heap where I prepared neighbouring chunks with fake free-list metadata, and shows that the resulting size-field corruption leads to forward consolidation, overlapping allocation, and controlled dispatch of a stand-in gadget. The overflow contributes one byte; the harness supplies the rest of the preconditions. This post explains the bug, the quiet byte, the exploitation path I found, and where the gaps remain.
PoC, detection rules, and live pcap: al4n4n/achilles-heel/CVE-2026-132825
A letter that grows
Every Ruby string carries an encoding. Today that is almost always UTF-8, Ruby’s default, and nothing in this post applies to UTF-8 strings. But Ruby still ships the legacy single-byte encodings: ISO-8859-1 through -16 and the Windows-125x code pages. Each has a small C file under enc/, and each of those files has a function called case_map that knows how to turn that encoding’s letters into upper case, lower case, title case or folded case.
In a single-byte encoding, changing case is almost always one byte in, one byte out. The exception is the German sharp s, ß, which sits at byte 0xDF in fourteen of these encodings. Its upper-case form is two letters, SS. One byte in, two bytes out. The PoC’s baseline request shows this on the live target before anything bad happens:
1 | > stra\xdfe (6 bytes) |
Six bytes in, seven out. That growth is why Ruby cannot change case in place. String#upcase ends up in rb_str_casemap in string.c, which allocates a separate output buffer, a mapping_buffer: a 24-byte header (capa, used, next) followed by the output space. The space is sized as the remaining input length plus 20, a constant named CASE_MAPPING_ADDITIONAL_LENGTH. Twenty spare bytes cover twenty sharp s. If the output grows more than that, the encoding’s case_map is expected to stop when the buffer is full, and rb_str_casemap links another buffer for the rest. That is what the next field is for.
The whole design rests on one promise: case_map stops before the end of the buffer. The last line of that excerpt says the baseline fits in a 26-byte buffer. The interesting question is what happens when it does not.
The vulnerable code
The fix commit says more than the advisory does. It is titled “Fix a heap buffer overflow in case mapping of the sharp s”, and it changes the same line in fourteen encoding files. Here is the loop it touches, from enc/iso_8859_1.c in Ruby 3.4.12, abridged, with my comments. The other thirteen files have the same pattern.
1 | 264 OnigUChar *to_start = to; |
to is the write position and to_end is one past the last byte of the buffer. The loop condition to < to_end asks: is there room for one more byte? For every character except one, that is the right question. For the sharp s under upcase, the body writes S at line 272, sets code to the second letter, and falls through to the common store at line 293. Two writes after a check for one.
So if the loop is entered with exactly one byte free and the next input byte is 0xDF, the first S takes the last byte of the buffer and the second one lands at to_end, one byte past the allocation. It is a textbook off-by-one, CWE-193, and the same loop sits in fourteen files: enc/iso_8859_{1,2,3,4,9,10,13,14,15,16}.c and enc/windows_{1250,1252,1254,1257}.c.
The same shape exists for the other operations that expand a sharp s. swapcase writes SS as well. downcase(:fold) writes ss. capitalize writes Ss for a leading sharp s. casecmp? folds its operands, so it goes through the same code. That gives five affected methods, plus their bang forms, and two possible values for the stray byte: S (0x53) or s (0x73).
Notice what the attacker does not get. The byte past the buffer is never an input byte. It is a letter the encoding table chose.
Counting to forty-one
The overflow needs the loop to arrive at a sharp s with exactly one byte free. Whether that happens is pure arithmetic on the input.
Take an input of n bytes. The first buffer has n + 20 bytes of output space. Every ordinary byte advances the write position by one, every sharp s by two. Say j ordinary bytes and k sharp s have been processed when the fatal sharp s comes up. One byte free means j + 2k = n + 19.
The fatal character is itself part of the input, so n is at least j + k + 1. Put that into the equation and k comes out as at least 20. In other words: the twenty spare bytes have to be used up by twenty sharp s before the twenty-first can do damage. No ordinary sentence does that. A crafted string does it trivially.
The smallest case has no ordinary bytes at all. With j = 0 the equation is 2k = n + 19, so n must be odd, and the smallest n that leaves room for the fatal character is 21. Twenty-one sharp s get a 41-byte output space. Twenty of them fill offsets 0 to 39. The twenty-first enters the loop at offset 40, where 40 < 41 holds, and writes S at 40 and S at 41. Offset 41 does not exist.
An all-sharp-s string of even length never hits the condition: the output space is even too, the write position moves in steps of two, and it goes from two bytes free straight to full without ever standing on the last byte. Mixed strings fix the parity. Seven a followed by 21 sharp s is 28 bytes and overflows just the same, and that particular shape matters later.
With the 24-byte header, the 21-byte input turns into a malloc request for 65 bytes, and the stray S is byte number 66.
A door
Ruby is a language runtime, so this bug needs a host: some application that takes text from the network, holds it in one of the fourteen encodings and changes its case. The advisory names none, so the lab uses the smallest honest stand-in I could write: a Sinatra 4.2.2 service on Puma 8.1.2 that upper-cases whatever a client posts, in the character set the client declares. This is the whole handler, from lab/app/app.rb:
1 | post "/upcase" do |
There is no memory-unsafe code here. The application reads the body, labels it with the declared encoding, rejects byte sequences that are invalid in that encoding, and calls upcase. In ISO-8859-1 every byte is a valid character, so 21 bytes of 0xDF pass the check as the perfectly legal string ßßßßßßßßßßßßßßßßßßßßß.
Treat this application as a lab deviation and judge it as one. Trusting the client’s charset parameter is a design choice I made so that one request is enough. A real target has to do two things on its own: hold attacker-controlled text in one of these encodings, and call one of the five methods on it. An application that lives entirely in UTF-8 is not reachable this way.
Two details in Ruby itself narrow the path a little further. A string with only 7-bit characters in a single-byte encoding takes a fast path in rb_str_upcase and never reaches case_map, so plain ASCII is not a trigger. And a call with the :ascii option does not reach it either.
The trigger, as the PoC sent it:
1 | [3] Trigger: POST /upcase with 0 x 'a' + 21 x 0xDF, declared ISO-8859-1 |
No cookie, no token, no session. 186 bytes on the wire.
One byte is quiet
Here is the part the advisory does not prepare you for. Send that request to a stock Ruby 3.4.12 and you get a polite 200. I checked that later, against a build without the sanitizer, and there is a section on it below. The overflow happens. Nothing notices.
A one-byte write past a 65-byte allocation lands in memory that the allocator rounded up and nobody uses. No crash, no log line, no changed response. A proof that says “the heap is corrupted, trust me” is not a proof, so the lab builds Ruby with AddressSanitizer, which surrounds every allocation with poisoned memory and reports the first access that touches it.
Both lab images are built from the official release tarballs, checksum-pinned, with clang 19 and the recipe from Ruby’s own doc/contributing/building_ruby.md: cflags='-fsanitize=address -fno-omit-frame-pointer -DUSE_MN_THREADS=0'. The source is not patched. The only difference between the two images is the tarball: 3.4.12, the last vulnerable release of its series, and 3.4.13, the first fixed one. During setup each image prints the loop guard it was compiled from, so the run itself shows which code is under test: while (*pp < end && to < to_end) { in one, while (*pp < end && to_end - to > 1) { in the other.
One more setting is mine: abort_on_error=1 in ASAN_OPTIONS, so that the sanitizer ends the process with abort() and the container’s exit status names the signal. That changes how the sanitizer dies, not what it detects.
Keep in mind what this means for everything in the next section. The abort you are about to see is the sanitizer’s. It is the instrument, not the bug’s natural behaviour.
The report
The request above never got an answer. This is the target’s own log, evidence/target-vuln-asan.txt, with my cuts marked:
1 | ==7==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x50700021c331 at pc 0x773253c25ef8 bp 0x77324ce7f810 sp 0x77324ce7f808 |
Read it in three parts.
The first block is the write. WRITE of size 1, in case_map, at enc/iso_8859_1.c:293. That is the common store from the listing above, the second byte of SS. It was called from rb_str_casemap, which was called from rb_str_upcase.
The second block is the victim. The address is “0 bytes after” a 65-byte region, and that region was allocated by rb_str_casemap at string.c:7834, inside the same upcase call. Sixty-five is the 24-byte header plus 41 bytes of output space, exactly what the arithmetic predicted. The region ends at 0x50700021c331 and the write is at 0x50700021c331.
The shadow bytes show the same thing as a picture. Each shadow byte describes eight bytes of real memory. The buffer starts sixteen bytes before the marked row, which is the 00 00 at the end of the row above. Then come six more 00, 48 fully usable bytes, and then [01]: a group of eight in which only the first byte may be touched. Sixteen plus 48 plus one is 65. Everything after it is fa, redzone. The brackets mark the group the write hit: it went for the second byte of a group that has one.
The third block is Ruby’s own crash handler, and it closes the chain from the network to the C function. /app/app.rb:41 is the text.upcase line of the handler. The control frames show CFUNC :upcase called from a block in app.rb, and the Ruby-level backtrace in the full log runs from Puma’s thread pool through Sinatra’s route dispatch down to those last two lines. This is the request handler, running my request.
From the outside, the same moment looks like this (evidence/poc-vuln.txt):
1 | < no HTTP response: the connection was closed after 0 bytes (0.56 s) |
Exit code 134 is SIGABRT, and oom_killed=false rules out the kernel’s out-of-memory killer. In the capture, the trigger request is packet #24 at 07:32:44.765917 on the lab host’s clock, which ran about 60 seconds ahead of the clock behind the “sent” line above. The target closes the connection 539 ms later without having sent a byte, and later connection attempts are reset. The script that printed these lines never had a shell on the target: with --container it reads the stopped container’s log and state afterwards, which is evidence collection, not part of the attack.
The overflow depends only on the request bytes, so it is deterministic. One request, one report.
Negative control
Same script, same request, same application, Ruby 3.4.13 (evidence/poc-patched.txt):
1 | > [\xdf * 21] (21 bytes) |
Forty-two S, the correct answer, and a server that is still there. The response is also a small demonstration of the buffer chain doing its job: 42 bytes of output cannot fit in a 41-byte space, so the fixed loop must have stopped after twenty sharp s and left the last one to a second buffer.
Without the sanitizer
I did not want to leave it at “ASAN says so”, because a sanitizer build is not what anyone runs in production. So I rebuilt the vulnerable image with the sanitizer flags removed and nothing else changed, and pointed the unmodified PoC at it.
A warning first: the runs in this section are not in the repository’s evidence set. The repository ships the smallest set of files that proves its claims, and these are not among them. Read this section as lab notes.
The default 21-byte request did nothing, 200 times in a row. Every one was answered with a 200.
The reason is in how glibc sizes its chunks. The lab’s glibc is 2.41. For a 65-byte request it hands out a chunk with 72 usable bytes, so byte number 66 falls into seven bytes of slack that belong to the same chunk. Harmless.
Change the input length and the picture changes. A 28-byte input makes the request 72 bytes, the chunk has no slack at all, and byte number 73 is the first byte of whatever comes next in memory. In glibc that is the size field of the next chunk. This is where the seven a plus 21 sharp s from earlier come in: poc.py --prefix 7 --count 21 sends exactly that shape.
The stray byte overwrites the low byte of that size field, which is also where glibc keeps its flag bits. In a small simulation with the same glibc, a neighbour whose size field read 0x51 came out as 0x53 or 0x73, and both values set the flag that says “this chunk came from mmap”. Nothing happens at that moment. Later, when the program frees the neighbour, glibc treats it as a mapped chunk, finds that it is not a valid one, prints munmap_chunk(): invalid pointer and aborts.
Over HTTP, against the stock build, that is what I saw. In the first container the 74th request got no answer and the process was gone with SIGABRT and that message at the end of its log. Three more fresh containers went the same way after 976, 967 and 925 requests. All the requests before the fatal one were answered correctly. A bare Ruby script that made the same upcase call 2000 times on the lab’s stock binary survived, while an earlier probe with the same script in the official ruby:3.4.12-slim image aborted with the same message. Whether the damaged neighbour is ever freed depends on the heap layout, and a web server’s heap frees a lot.
If you try this yourself, know that the shipped poc.py does not count it as a hit. It attributes a stop to the bug only when it finds a sanitizer report, and against a stock build it prints RESULT: not confirmed: the stop is not attributed to the overflow (exit 1). That is deliberate. A dead process alone is not proof of this bug, and the repository’s claims stay with the sanitizer build, where the target itself names the function and the line.
What one byte buys
What I can prove is narrow and solid: a pre-authentication, single-request, one-byte out-of-bounds heap write in the Ruby runtime, reached over the network through an ordinary web stack, with the target-side report and a negative control.
What the advisory describes is more: remote code execution. The Ruby team says PoCs exist that reach it in some scenarios, and I have no reason to doubt them. I did not get there over the network. But the one-byte write is not stuck at a crash.
The value is fixed. The byte is S or s, chosen by the method the application calls, not by the attacker.
The position is fixed. It is always the first byte past the mapping buffer. The attacker chooses the input length, and with it the size class the buffer is allocated from. Nothing else.
There is no read side. The HTTP response is copied out of the mapping buffer within bounds, and no code path returns the stray byte or anything near it.
But the byte does reach something useful. On glibc, when the input is long enough that the mapping buffer lands above the tcache threshold (1004 bytes, chunk 1056), the byte overwrites the low byte of the next chunk’s size field. The value 0x73 from downcase(:fold) inflates the neighbour’s apparent size from 80 to 112 bytes, and glibc’s forward-consolidation path on the mapping-buffer free does not check IS_MMAPPED on the corrupted neighbour. It merges the two chunks, and a subsequent allocation of the merged region overlaps 24 bytes into the object that follows.
I demonstrated this end-to-end on the stock vulnerable build (Ruby 3.4.12, glibc 2.41, no sanitizer) in an in-process harness (source in the repo). The harness initializes the Ruby VM, grooms the heap by draining all tcache bins and allocating the layout from the top chunk, then writes fake free-list metadata (fd/bk pointers for glibc’s safe-unlink check, and a fake next-chunk header) into the neighbouring allocations. It creates the 1004-byte ISO-8859-1 string, frees the placeholder to open a hole, then calls String#downcase(:fold) through rb_funcall. The real Ruby case_map overflows 0x73 onto the neighbour’s size field (the overflow’s one-byte contribution); the mapping-buffer free consolidates the chunks using the harness-prepared metadata; a follow-up allocation overlaps into the next object; and a function-pointer overwrite dispatches a stand-in gadget. Exit 0.
The overflow contributes the size-field corruption; the harness supplies the rest of the preconditions (heap layout, fake metadata, stand-in gadget at a known address). What remains for a remote exploit: attacker control of neighbouring chunk contents (the fd/bk pointers and next-chunk header the harness writes directly), remote heap grooming over HTTP, a heap-address leak to bypass ASLR, and a real gadget such as a corrupted klass pointer or RTypedData function pointer. None of that was built.
| Claim | Status | Evidence |
|---|---|---|
The 21 × 0xDF ISO-8859-1 request makes Ruby 3.4.12 write one byte past a heap buffer in case_map (enc/iso_8859_1.c:293), reached through String#upcase in the request handler |
Proven | evidence/poc-vuln.txt, evidence/target-vuln-asan.txt |
| The request arrives over HTTP with no credentials, and nothing else is done to the target | Proven | capture/exploit.pcap (packet #24), poc.py |
| The sanitizer build aborts (SIGABRT, exit 134) and the service goes down | Proven | evidence/poc-vuln.txt; capture packets #26 and #36 to #44 |
| Ruby 3.4.13 handles the same request correctly | Confirmed (negative control run) | evidence/poc-patched.txt |
| In-process code-execution chain (stand-in gadget, real Ruby overflow) | Proven (in-process, stand-in gadget) | evidence/impact-vuln-stock-inprocess.txt, source poc/ruby_consol_probe.c. The harness writes fake free-list metadata into neighbouring chunks, then triggers the real overflow (one byte, 0x73, on the adjacent size field). Forward consolidation, overlapping allocation and controlled dispatch follow. The overflow contributes the size-field corruption; the harness supplies the rest. Exit 0 |
| Remote code execution against the product | Not reached | the in-process harness uses C-level heap grooming, harness-written fake chunk metadata, and a stand-in gadget at a known address; a product-level exploit would additionally need attacker control of neighbouring chunk contents, remote heap grooming over HTTP, a heap-address leak and a real gadget |
| The other 13 encodings and the other four methods | Not reached | not run; the fix diff shows the same pattern in all 14 files, and poc.py --charset selects another encoding |
“Not reached” describes where this work stopped. It is not a statement about the bug.
I tested one Ruby series (3.4), one encoding (ISO-8859-1), one method (upcase) and one application, on x86_64 Linux.
Detection
The repository has two Suricata rules and one Sigma rule. All three are experimental / minimally validated: each was tested only against the attack capture or target log from this lab and one benign sample. I make no claim about coverage or false-positive rates.
The first Suricata rule looks for the two things the request cannot do without, a legacy charset and a run of sharp s:
1 | alert http any any -> any any (msg:"CVE-2026-132825 Ruby case-conversion heap overflow - sharp s cluster in ISO-8859 request"; flow:established,to_server; http.content_type; content:"charset="; nocase; content:"iso-8859"; nocase; http.request_body; content:"|df df df df df df df df df df df df df df df df df df df df df|"; fast_pattern; reference:cve,2026-132825; classtype:attempted-admin; metadata:created_at 2026_11_19, cve CVE_2026_132825, signature_severity Major, confidence Medium, performance_impact Low, author al4n4n; sid:1000001; rev:1;) |
It fired once on capture/exploit.pcap, on the trigger request, and stayed silent on a benign request that posts a word with a single sharp s to the same endpoint. The second rule, sid 1000002, is the same with windows-125 as the charset. It loads cleanly and was silent on the benign sample, but it has not fired on anything, because my capture uses ISO-8859-1.
The limits are easy to state. The rules need plaintext HTTP or TLS termination in front of the sensor. They match 21 consecutive 0xDF bytes, and the arithmetic above shows that the sharp s do not have to be consecutive: a payload that spreads them among other characters still overflows and is not matched. And HTTP is only one way to hand text to a Ruby program.
The Sigma rule watches the Ruby process output for the crash: heap-buffer-overflow together with case_map, or [BUG] ASAN error together with upcase, or glibc’s munmap_chunk(): invalid pointer. The first two match the log of the vulnerable run and not the patched one. The third is there for builds without a sanitizer; it has no sample in the repository and it will fire on any heap corruption glibc catches that way, whatever the cause. Details are in detection/README.md.
The fix
The fix is one line, fourteen times:
1 | case_map(OnigCaseFoldType* flagP, const OnigUChar** pp, |
to_end - to > 1 means: enter the loop only when two bytes are free. That is the most any single character in these encodings can produce, so no iteration can overrun. The cost is that the loop now sometimes stops with one byte unused, and rb_str_casemap links another buffer a little earlier than it strictly had to. The negative control above is consistent with exactly that.
The commit also adds a test that walks all fourteen encodings and every length from 1 to 64 through upcase, downcase(:fold), swapcase, capitalize and casecmp?. Ruby 3.4.13 fixes several advisories at once, so I also diffed the 3.4.12 and 3.4.13 tarballs to make sure the lab compares what I think it compares: all fourteen files carry the same one-line change.
The Ruby team’s recommendation is to upgrade to 3.3.14, 3.4.13 or 4.0.10.
Advisory and fix
| Date | Event |
|---|---|
| 2026-10-28 | Fix commit b841d6f authored, “Fix a heap buffer overflow in case mapping of the sharp s” |
| 2026-11-18 | Ruby security advisory posted; Ruby 3.3.14, 3.4.13 and 4.0.10 released |
| 2026-11-20 | Reproduction and write-up |
Advisory: Security advisories: multiple vulnerabilities in Regexp and String case conversion and GHSA-34m4-m9fh-gqp5. The advisory credits Stephan Lipp (Ada Logics) and Anthropic with the report. No CVSS vector has been published; the 7.4 score comes from external sources, and the GitHub advisory labels the bug Critical.
Reproduction
Readers can verify every claim in the table from the repository. You need Python 3.8 or later and Docker with BuildKit on an x86_64 Linux host. The first run compiles Ruby twice with the sanitizer, which takes a few minutes.
1 | git clone https://github.com/al4n4n/achilles-heel.git |
The raw output of every run quoted here, the capture and the rules are in the repository: al4n4n/achilles-heel/CVE-2026-132825.