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.
Originally disclosed on Cisco Talos
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.
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
- Open a Gerber or Excellon file in KiCad's Gerber Viewer.
- The file contains a line starting with 'G' or 'D' followed by a long sequence of numeric characters.
- The parser calls GCodeNumber or DCodeNumber, which copies the numeric characters into a 1024-byte stack buffer.
- 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.