Skip to content
Memory corruption Advisory Advanced CVE-2021-40400

Gerbv RS-274X aperture macro outline primitive out-of-bounds read vulnerability

A crafted RS-274X Gerber file can make the aperture macro outline primitive copy more parameters than the virtual stack holds, causing an out-of-bounds read of heap memory. The leaked heap data is used to draw the shape, so an attacker who can view the rendered image may be able to extract process memory contents.

Claudio Bozzato Follow

Originally disclosed on Cisco Talos

Critical 9.3 View original

An out-of-bounds read vulnerability exists in the RS-274X aperture macro outline primitive functionality of Gerbv 2.7.0 and dev (commit b5f1eacd) and the forked version of Gerbv (commit d7f42a9a). A specially-crafted Gerber file can lead to information disclosure.

Claudio Bozzato, on Cisco Talos

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 stack buffer is sized from the number of pushed values (nuf_push), but the memcpy length is taken from an attacker-controlled vertex count (nuf_parameters), so the copy can read beyond the stack allocation.

Impact

The out-of-bounds read could leak heap metadata or process memory through the rendered image, though the quality of the leak depends on the chosen dpi and on heap manipulation.

What the attacker needed

Ability to supply a Gerber file; victim or service renders the file; attacker can view the rendered image

How it was found

  1. Create a Gerber file that passes the RS-274X detection checks.
  2. Define an aperture macro whose outline primitive declares a vertex count larger than the number of values actually pushed.
  3. Instantiate that macro with an AD command so the virtual machine runs it.
  4. Open or export the file with Gerbv; the parameter copy reads past the stack and the rendered shape reflects nearby heap data.

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 turns circuit-board design files into pictures. A file can describe a shape with a list of points, and the program copies those points from a small temporary buffer into another buffer. The file can claim there are more points than were actually supplied, so the program reads past the end of the buffer and copies whatever memory sits next to it into the picture.

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.

More by Claudio Bozzato

View all

185 more disclosed reports, best first.

More from Cisco Talos

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.