The vulnerability CVE-2022-46294 describes an out-of-bounds write in the MOPAC input parser of Open Babel. The provided patch in commit 40e852138f21d586b7ccdce6329e7b23a87168bb addresses this and several other related vulnerabilities (CVE-2022-46291, CVE-2022-46292, CVE-2022-46293, CVE-2022-46295) across different file format parsers. The root cause for all of them is the same: writing to a fixed-size translationVectors array of size 3 without checking the number of elements already present. A malicious file could provide more than three translation vectors, causing a buffer overflow on the stack.
The primary vulnerable function for CVE-2022-46294 is OpenBabel::MOPACCARTFormat::ReadMolecule, which is responsible for reading MOPAC input files. The patch adds the if (numTranslationVectors < 3) check to prevent writing more than three vectors. The analysis includes other functions from the same commit that were patched for the exact same vulnerability pattern in other file parsers, as they would also appear in a runtime profile if a similarly crafted file of their respective format was opened.