KiCad EDA Gerber Viewer gerber and excellon coordinates parsing stack-based buffer overflow vulnerability
Two stack-based buffer overflows exist in KiCad's Gerber Viewer when parsing coordinate values from Gerber or Excellon files. A crafted file with a long numeric coordinate line can overflow a fixed 256-byte stack buffer, potentially leading to code execution.
Originally disclosed on Cisco Talos
Multiple stack-based buffer overflow vulnerabilities exist in the Gerber Viewer gerber and excellon coordinates 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 coordinate parsing loops copy every numeric character into a fixed 256-byte stack buffer without checking its bounds.
Impact
A crafted Gerber or Excellon file could cause a stack buffer overflow that may lead to code execution when the victim opens it.
What the attacker needed
Victim opens a crafted Gerber or Excellon file
How it was found
- Open a Gerber or Excellon file in the Gerber Viewer.
- The file is read line by line into a large line buffer.
- A line beginning with X or Y (or I or J) triggers coordinate parsing.
- The parser copies consecutive numeric characters into a 256-byte stack buffer without a length check.
- A long enough numeric line overflows the buffer, as confirmed by AddressSanitizer.
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.
KiCad is software for designing circuit boards, and its Gerber Viewer opens files describing circuit layouts. When it reads a coordinate line, it copies the digits into a small fixed-size box on the stack (a region of memory used for temporary data) without checking how much fits. A malicious file with a very long number line spills past that box and can overwrite nearby memory, which may 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.