R PDF LoadEncoding Code Execution Vulnerability
The PDF device in R copies each entry from a user-supplied encoding file into a fixed 40-byte buffer without checking its length, so an overlong entry overflows memory. An attacker who can get a crafted R script run could corrupt memory and potentially execute code.
Originally disclosed on Cisco Talos
An exploitable buffer overflow vulnerability exists in the LoadEncoding functionality of the R programming language version 3.3.0. A specially crafted R script can cause a buffer overflow resulting in a memory corruption.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The code uses an unbounded string copy into a 40-byte buffer for each encoding name without checking the length of the input.
Impact
The overflow corrupts memory and could potentially be leveraged to gain remote code execution, though the report only says this could happen later in the program.
What the attacker needed
Victim runs a crafted R script; attacker controls the encoding file
How it was found
- Create an R script that opens a PDF device and points its encoding option at a file you control.
- Put an entry longer than 40 characters in that encoding file.
- Run the script so R loads the encoding file and copies the long entry into the fixed buffer.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
R is a language for statistics, and it can write PDF files using a font encoding file the user names. That file is read line by line and each name is copied into a small fixed-size slot in memory. If a name is longer than the slot, it spills into neighbouring memory, which can crash the program or let an attacker take control of it.
What is Memory corruption?
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.