CVE-2026-41197: CWE-131: Incorrect Calculation of Buffer Size in noir-lang noir
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.
AI Analysis
Technical Summary
Noir-lang's noir compiler incorrectly calculates the memory allocation size for nested arrays returned by foreign function calls when compiling to Brillig bytecode. The bug arises because the allocation function uses the semantic length of nested arrays instead of the semi-flattened size that accounts for composite element types consuming multiple memory slots. This under-allocation causes heap corruption in the Brillig VM when nested arrays of tuples or other composite types are returned. The vulnerability is tracked as CWE-131 (Incorrect Calculation of Buffer Size) and has a CVSS 4.0 score of 9.3, indicating critical severity. The issue is resolved in noir version 1.0.0-beta.19.
Potential Impact
Heap corruption in the Brillig VM can occur when foreign calls return nested arrays of composite types due to under-allocation of memory. This can lead to undefined behavior, potential crashes, or other memory safety issues within the noir-lang environment. The vulnerability is exploitable remotely without authentication and requires no user interaction, increasing its risk.
Mitigation Recommendations
Upgrade noir-lang noir to version 1.0.0-beta.19 or later, where this buffer size calculation bug is fixed. No other mitigations are indicated. Patch status is not explicitly stated in the vendor advisory, but the fix is included in the specified version.
CVE-2026-41197: CWE-131: Incorrect Calculation of Buffer Size in noir-lang noir
Description
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.
CVSS v4.0
Score 9.3critical
Weaknesses
AI-Powered Analysis
Machine-generated threat intelligence
Technical Analysis
Noir-lang's noir compiler incorrectly calculates the memory allocation size for nested arrays returned by foreign function calls when compiling to Brillig bytecode. The bug arises because the allocation function uses the semantic length of nested arrays instead of the semi-flattened size that accounts for composite element types consuming multiple memory slots. This under-allocation causes heap corruption in the Brillig VM when nested arrays of tuples or other composite types are returned. The vulnerability is tracked as CWE-131 (Incorrect Calculation of Buffer Size) and has a CVSS 4.0 score of 9.3, indicating critical severity. The issue is resolved in noir version 1.0.0-beta.19.
Potential Impact
Heap corruption in the Brillig VM can occur when foreign calls return nested arrays of composite types due to under-allocation of memory. This can lead to undefined behavior, potential crashes, or other memory safety issues within the noir-lang environment. The vulnerability is exploitable remotely without authentication and requires no user interaction, increasing its risk.
Mitigation Recommendations
Upgrade noir-lang noir to version 1.0.0-beta.19 or later, where this buffer size calculation bug is fixed. No other mitigations are indicated. Patch status is not explicitly stated in the vendor advisory, but the fix is included in the specified version.
Technical Details
- Data Version
- 5.2
- Assigner Short Name
- GitHub_M
- Date Reserved
- 2026-04-18T02:51:52.973Z
- Cvss Version
- 4.0
- State
- PUBLISHED
- Remediation Level
- null
Threat ID: 69e9707c87115cfb68522138
Added to database: 4/23/2026, 1:06:04 AM
Last enriched: 4/30/2026, 8:04:31 AM
Last updated: 6/6/2026, 12:37:30 PM
Views: 131
Community Reviews
0 reviewsCrowdsource mitigation strategies, share intel context, and vote on the most helpful responses. Sign in to add your voice and help keep defenders ahead.
Want to contribute mitigation steps or threat intel context? Sign in or create an account to join the community discussion.
Actions
Updates to AI analysis require Pro Console access. Upgrade inside Console → Billing.
Need more coverage?
Upgrade to Pro Console for AI refresh and higher limits.
For incident response and remediation, OffSeq services can help resolve threats faster.
Latest Threats
Check if your credentials are on the dark web
Instant breach scanning across billions of leaked records. Free tier available.