CVE-2023-25399 Overview
A reference counting issue that leads to a potential memory leak was discovered in SciPy in the Py_FindObjects() function. This vulnerability stems from improper reference counting in Python's C API usage within the SciPy library, which can result in memory not being properly freed during object operations.
Critical Impact
This issue can lead to memory exhaustion through repeated invocations of the affected function, potentially causing denial of service conditions in long-running applications that utilize SciPy's image processing capabilities.
Important Note: This CVE is disputed by the SciPy maintainers, who classify it as a bug rather than a security vulnerability. According to the project maintainers, SciPy is not designed to be exposed to untrusted users or data directly.
Affected Products
- SciPy (all versions prior to the fix in commit 8627df31ab)
- Applications using SciPy's scipy.ndimage module
- Python environments with vulnerable SciPy installations
Discovery Timeline
- 2023-07-05 - CVE-2023-25399 published to NVD
- 2024-11-21 - Last updated in NVD database
Technical Details for CVE-2023-25399
Vulnerability Analysis
The vulnerability exists in the Py_FindObjects() function within SciPy's codebase. This function is part of SciPy's image processing capabilities, specifically within the scipy.ndimage module used for multi-dimensional image processing operations.
The core issue involves improper reference counting when handling Python objects in the C extension code. In Python's C API, objects must have their reference counts properly incremented and decremented to ensure correct memory management. When a reference count is not properly decremented (missing Py_DECREF call), the object's memory is never freed, leading to a memory leak.
The disputed nature of this CVE is significant context for security teams. The SciPy maintainers have noted that the library is intended to be used in trusted computational environments where the input data is controlled, rather than as a public-facing service handling untrusted input.
Root Cause
The root cause is a reference counting error (CWE-401: Missing Release of Memory after Effective Lifetime) in the C extension code. When objects are created or borrowed in Python's C API, the developer must manually manage reference counts. In this case, the Py_FindObjects() function fails to properly decrement reference counts for certain Python objects, causing those objects to persist in memory indefinitely.
This type of bug is common in Python C extensions where developers must manually track object lifetimes, unlike pure Python code where garbage collection handles memory management automatically.
Attack Vector
Exploitation requires local access to execute Python code that calls the vulnerable function. An attacker with the ability to execute arbitrary Python code on a system could repeatedly invoke the Py_FindObjects() function to gradually exhaust available memory, leading to a denial of service condition.
The attack scenario would involve:
- Gaining access to execute Python code on the target system
- Importing SciPy and calling the vulnerable function in a loop
- Gradually consuming system memory until the application or system becomes unresponsive
Given the local attack vector and the requirement to execute arbitrary code, the practical exploitability is limited. Systems that already allow arbitrary code execution are typically vulnerable to more direct forms of denial of service.
Detection Methods for CVE-2023-25399
Indicators of Compromise
- Gradual memory consumption increase in Python processes using SciPy
- Applications using scipy.ndimage experiencing memory growth over time
- System memory pressure without corresponding increase in active data processing
- Python processes with unexpectedly high resident memory usage
Detection Strategies
- Monitor memory usage patterns for Python processes utilizing SciPy libraries
- Implement application-level memory profiling to detect gradual memory growth
- Use Python memory profilers like tracemalloc to identify unreleased objects
- Check installed SciPy versions against known vulnerable versions
Monitoring Recommendations
- Set up alerts for memory usage thresholds on systems running SciPy-dependent applications
- Implement process monitoring to detect abnormal memory growth patterns
- Review application logs for out-of-memory errors or process crashes
- Establish baseline memory profiles for normal application operation
How to Mitigate CVE-2023-25399
Immediate Actions Required
- Update SciPy to the latest version that includes the fix from Pull Request #16397
- Review applications for usage of scipy.ndimage.find_objects() function
- Implement memory monitoring for critical SciPy-dependent applications
- Assess whether your deployment exposes SciPy to untrusted inputs
Patch Information
The fix for this issue has been implemented in the SciPy repository. The patch addresses the reference counting issue by ensuring proper Py_DECREF calls are made for all Python objects created or borrowed during the Py_FindObjects() function execution.
For detailed information about the fix, refer to:
Workarounds
- Limit exposure of SciPy functionality to trusted users and data sources only
- Implement application-level memory limits using resource controls or container constraints
- Periodically restart long-running processes that use the affected functionality
- Consider isolating SciPy operations in separate processes that can be safely terminated and restarted
# Configuration example - Update SciPy to the latest version
pip install --upgrade scipy
# Alternatively, install a specific patched version
pip install scipy>=1.11.0
# Verify installed version
pip show scipy | grep Version
Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

