Skip to content
Memory corruption Advisory Advanced CVE-2022-23947CVE-2022-23946

KiCad EDA Gerber Viewer gerber and excellon GCode/Dcode parsing stack-based buffer overflow vulnerability

The Gerber and Excellon file parsers in KiCad's Gerber Viewer copy numeric characters from a line into a fixed-size stack buffer without checking the length, causing a stack-based buffer overflow. An attacker could provide a malicious file to trigger the overflow and potentially execute code.

Claudio Bozzato Follow

Originally disclosed on Cisco Talos

High 7.8 View original

Multiple stack-based buffer overflow vulnerabilities exist in the Gerber Viewer gerber and excellon GCode/Dcode parsing functionality of KiCad EDA 6.0.1 and master commit de006fc010. A specially-crafted gerber or excellon 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

The GCodeNumber and DCodeNumber functions copy an unbounded number of numeric characters from the input line into a fixed 1024-byte stack buffer without any bounds check.

What the attacker needed

Victim opens a malicious file

How it was found

  1. Open a Gerber or Excellon file in KiCad's Gerber Viewer.
  2. The file contains a line starting with 'G' or 'D' followed by a long sequence of numeric characters.
  3. The parser calls GCodeNumber or DCodeNumber, which copies the numeric characters into a 1024-byte stack buffer.
  4. The copy exceeds the buffer size, causing a stack-based buffer overflow.

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.

A buffer overflow happens when a program writes more data into a fixed-size memory area than it can hold, spilling into nearby memory. Here, when KiCad reads a Gerber or Excellon file, it copies a long string of digits into a small 1024-byte space on the stack without checking the length. This can crash the program or, in the worst case, 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.