{"id":"CVE-2026-41197","published":"2026-04-23T00:35:37Z","modified":"2026-04-25T03:55:38Z","title":"Brillig: Heap corruption in foreign call results with nested tuple arrays","vendor":"noir-lang","product":"noir","tier":"tail","description":{"text":"Noir is a Domain Specific Language for SNARK proving systems that is designed to use any ACIR compatible proving system, and Brillig is the bytecode ACIR uses for non-determinism. Noir programs can invoke external functions through foreign calls. When compiling to Brillig bytecode, the SSA instructions are processed block-by-block in `BrilligBlock::compile_block()`. When the compiler encounters an `Instruction::Call` with a `Value::ForeignFunction` target, it invokes `codegen_call()` in `brillig_call/code_gen_call.rs`, which dispatches to `convert_ssa_foreign_call()`. Before emitting the foreign call opcode, the compiler must pre-allocate memory for any array results the call will return. This happens through `allocate_external_call_results()`, which iterates over the result types. For `Type::Array` results, it delegates to `allocate_foreign_call_result_array()` to recursively allocate memory on the heap for nested arrays. The `BrilligArray` struct is the internal representation of a Noir array in Brillig IR. Its `size` field represents the semi-flattened size, the total number of memory slots the array occupies, accounting for the fact that composite types like tuples consume multiple slots per element. This size is computed by `compute_array_length()` in `brillig_block_variables.rs`. For the outer array, `allocate_external_call_results()` correctly uses `define_variable()`, which internally calls `allocate_value_with_type()`. This function applies the formula above, producing the correct semi-flattened size. However, for nested arrays, `allocate_foreign_call_result_array()` contains a bug. The pattern `Type::Array(_, nested_size)` discards the inner types with `_` and uses only `nested_size`, the semantic length of the nested array (the number of logical elements), not the semi-flattened size. For simple element types this works correctly, but for composite element types it under-allocates. Foreign calls returning nested arrays of tuples or other composite types corrupt the Brillig VM heap. Version 1.0.0-beta.19 fixes this issue.","provenance":"source","from":"CVE.org"},"cvss":{"score":9.3,"severity":"CRITICAL","version":"4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N","provenance":"source","from":"CVE.org CNA"},"epss":{"score":0.00411,"percentile":0.36199,"provenance":"source"},"cwes":[{"id":"CWE-131","name":"Incorrect Calculation of Buffer Size"}],"references":[{"url":"https://github.com/noir-lang/noir/security/advisories/GHSA-jj7c-x25r-r8r3","tags":["x_refsource_CONFIRM"]},{"url":"https://github.com/noir-lang/noir/releases/tag/v1.0.0-beta.19","tags":["x_refsource_MISC"]}],"priority":{"score":13.7,"factors":[{"name":"EPSS percentile","points":7.24},{"name":"CVSS severity","points":6.51}]},"vendorSlug":"noir-lang","affectedVersions":[{"vendor":"noir-lang","product":"noir","versions":["< 1.0.0-beta.19"]}],"ssvc":{"exploitation":"none","automatable":"yes","technicalImpact":"total","timestamp":"2026-04-24T00:00:00+00:00","from":"CISA ADP","provenance":"source"},"affected":[{"ecosystem":"crates.io","package":"brillig","vulnerableRanges":["<1.0.0-beta.19"],"patched":["1.0.0-beta.19"],"from":["GHSA-jj7c-x25r-r8r3"],"provenance":"source"}],"summary":{"text":"The flaw is a heap corruption bug in the Brillig bytecode compiler of the noir language (noir-lang/noir), in the code that pre-allocates memory for foreign call results: for nested arrays it allocates using the logical element count rather than the semi-flattened size, so arrays of tuples or other composite types are under-allocated. An attacker who can supply or influence a program that makes a foreign call returning such nested arrays, with no authentication or user interaction required and over the network, can corrupt the Brillig VM heap.","provenance":"ai","model":"claude-haiku-5-5","generatedAt":"2026-11-20T21:37:46Z"},"euvd":{"id":"EUVD-2026-25156","exploited":false,"provenance":"source"}}