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

Gerbv RS-274X aperture macro outline primitive integer overflow vulnerability

An integer overflow in Gerbv's handling of the RS-274X aperture macro outline primitive allows a crafted Gerber file to cause a heap buffer overflow, potentially leading to code execution. An attacker can provide a malicious file to trigger this vulnerability.

Claudio Bozzato Follow

Originally disclosed on Cisco Talos

Critical 10.0 View original

An integer overflow 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 71493260). A specially-crafted gerber file can lead to code execution.

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

Likely an integer overflow in the calculation of the number of parameters for an outline primitive, which bypasses a size check and leads to an out-of-bounds memcpy.

Impact

A crafted file could cause a heap buffer overflow, potentially leading to code execution.

What the attacker needed

Ability to supply a crafted Gerber file

The fix

The vendor patched the vulnerability.

How it was found

  1. Create a Gerber file that is recognised as RS-274X (contains required markers and only printable characters).
  2. Define an aperture macro with an outline primitive (code 4) and a large number of vertices.
  3. Use an AD command to instantiate the macro, causing the virtual machine to execute the primitive.
  4. The integer overflow in nuf_parameters calculation bypasses the size check and leads to an out-of-bounds memcpy.

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 files describing circuit boards. A specially made file can cause the program to write more data than it has space for, 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.

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.