Gerbv RS-274X format aperture macro variables out-of-bounds write vulnerability
Gerbv does not check the bounds of the array that holds aperture macro variables, so a crafted RS-274X Gerber file can make it write a chosen value outside that array. An attacker could use this to corrupt memory and potentially execute code when the file is parsed.
Originally disclosed on Cisco Talos
An out-of-bounds write vulnerability exists in the RS-274X aperture macro variables handling functionality of Gerbv 2.7.0 and dev (commit b5f1eacd) and the forked version of Gerbv (commit 71493260). A specially-crafted gerber file can lead to code execution.
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 variable number from the file is used directly as an index into the fixed-size parameter array without any bounds check, so assignments and reads can go outside the array.
Impact
A malicious Gerber file could corrupt memory and lead to code execution, and because such files may be uploaded to manufacturer websites for conversion, the flaw could be reached over the network without user interaction.
What the attacker needed
A crafted Gerber file; the file is parsed by Gerbv
The fix
The vendor patched the issue, and the code should validate that variable numbers stay within the bounds of the parameter array before reading or writing it.
How it was found
- Create a file that passes the RS-274X detection checks, for example by including the required markers and only printable characters.
- Inside an aperture macro definition, add a variable assignment that uses an out-of-range variable number.
- Open the file with Gerbv, for example using the export switch to convert it to an image.
- The parser runs the macro in its virtual machine and writes the value outside the parameter array.
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.
Gerbv is a program that reads Gerber files, which describe the layers of a printed circuit board. A variable in these files is stored in a fixed-size list, and the program uses the variable's number as a position in that list without checking it is valid. By using a very large or negative number, an attacker can make the program write outside the list and overwrite other memory, which can crash it or let an attacker run their own code.
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.