/

CVE-2026-50144

Severity:

HIGH RISK

(7.1)

Heap Buffer Overflow (CWE-787) in ncnn Param Loader

CVE-2026-50144

Awaiting Analysis

Vulnerability type

Category:

Memory Corruption / Heap Buffer Overflow

CWE:

CWE-20, CWE-129, CWE-787

Impact:

Heap Memory Corruption and Potential Code Execution

Severity:

HIGH RISK

(7.1)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

A heap out-of-bounds write vulnerability in ncnn's parameter loading logic allows malicious .param model files to corrupt heap memory when parsed.

If an attacker can supply or replace the model parameter file, they may be able to trigger memory corruption, potentially leading to crashes or code execution during neural network initialization.

Affected context

This vulnerability occurs in applications that embed the ncnn inference framework and dynamically load model definitions from .param files.

It becomes relevant when the model parameters are not fully trusted—for example, when they are downloaded, side-loaded, or otherwise modifiable by an attacker or untrusted party.

The issue is specifically in ncnn::ParamDict::load_param() invoked by Net::load_param(), where parameter IDs derived from the file can cause incorrect indexing into an internal parameter array.

Exploit preconditions

  • Attack surface: Parsing of .param model files by ncnn at runtime
  • Required access: Ability to provide, replace, or tamper with the .param file consumed by Net::load_param()
  • Trigger point: Loading a crafted model file that encodes a negative or otherwise invalid parameter ID
  • Why exploitation is possible: The code validates only that id >= NCNN_MAX_PARAM_COUNT, but does not reject negative IDs, allowing them to be used as indices and write before the start of the params[NCNN_MAX_PARAM_COUNT] heap array

Why this happens

The underlying bug is improper validation of externally supplied indices prior to array access.

When parsing a .param file, the parameter ID is treated as an array index and only checked against a maximum boundary (id >= NCNN_MAX_PARAM_COUNT), without enforcing a non-negative lower bound.

This maps to CWE-129: Improper Validation of Array Index and CWE-787: Out-of-bounds Write, where untrusted input controls the index used for writing into a fixed-size array.

Additionally, the broader issue reflects CWE-20: Improper Input Validation, as the model file content is not comprehensively validated before being used in memory accesses.

Potential impact

  • Application crashes due to heap corruption when loading a malicious model file
  • Silent data corruption affecting model parameters or adjacent heap structures
  • Potential execution of attacker-controlled code, depending on allocator behavior and surrounding mitigations
  • Denial of service for services that perform inference on user-supplied or third-party models

General mitigation guidance

Mitigation generally focuses on tightening input validation around indices and constraining trust in model files.

Common defensive patterns include:

  • Enforcing both upper and lower bounds on IDs and indices before accessing arrays (e.g., requiring 0 <= id && id < MAX)
  • Treating model files as untrusted input and performing robust structural and semantic validation before loading them into core data structures
  • Using safer container abstractions or checked-access helpers instead of raw arrays where practical
  • Applying defense-in-depth measures such as compiler hardening flags, heap hardening, and running inference components with least-privilege and sandboxing to limit the blast radius of memory corruption

How teams detect issues like this

Potential detection strategies include:

  • Static analysis rules that flag array or pointer writes using indices derived from external or file-based input without full range checking (both lower and upper bounds)
  • Code review checklists emphasizing validation of model and configuration parsers, with special attention to loop bounds and index arithmetic
  • Fuzz testing of model loading routines using malformed and random .param files to expose memory safety issues
  • Integration of memory-safety tooling (e.g., AddressSanitizer or similar) in CI pipelines to catch heap out-of-bounds writes under test workloads

Sources

SourceLink
github.comgithub.com/Tencent/ncnn/commit/5a0288f255daa6c3294f77109f67718e434ec020
github.comgithub.com/Tencent/ncnn/security/advisories/GHSA-jxmc-3mv6-7pwr

Frequently asked

questions

It can be, if the application downloads or accepts .param model files from remote sources (e.g., user uploads, remote repositories, or update channels). In purely offline deployments where only trusted, bundled models are used, the practical risk is lower.

An attacker needs the ability to provide or alter the .param model file that ncnn loads. This might involve write access to the model directory, control over a distribution channel, or the ability to upload models if the application supports user-supplied networks.

The general fix is to validate all indices derived from untrusted input by checking both lower (>= 0) and upper (< MAX) bounds before accessing arrays, and to centralize such checks in well-reviewed helper functions where possible.

Adopt strong input-validation practices for all parsers, combine them with regular fuzz testing of file and model loading paths, and use static analysis or review policies that specifically target index arithmetic and bounds checking in performance-critical C/C++ code.

Find out what's already
exploitable in your codebase.