CVE-2025-58050 Overview
CVE-2025-58050 is a heap-buffer-overflow read vulnerability in the PCRE2 (Perl Compatible Regular Expressions 2) library, a widely-used set of C functions that implement regular expression pattern matching. The vulnerability exists within the handling of the (*scs:...) (Scan SubString) verb when combined with (*ACCEPT) in src/pcre2_match.c. This flaw affects version 10.45 of the library and may potentially lead to information disclosure if the out-of-bounds data read during the memcmp operation affects the final match result in a way observable by an attacker.
Critical Impact
This heap-buffer-overflow read vulnerability in PCRE2's regex matching engine could allow attackers to potentially disclose sensitive information through crafted regular expression patterns, affecting applications that rely on PCRE2 for pattern matching.
Affected Products
- PCRE2 version 10.45
- Applications and systems using PCRE2 10.45 for regular expression processing
- Any software dependent on the vulnerable pcre2_match.c component
Discovery Timeline
- 2025-08-27 - CVE CVE-2025-58050 published to NVD
- 2025-09-09 - Last updated in NVD database
Technical Details for CVE-2025-58050
Vulnerability Analysis
The vulnerability is classified under CWE-122 (Heap-based Buffer Overflow) and CWE-787 (Out-of-bounds Write). The flaw resides in the PCRE2 regular expression matching engine's handling of the Scan SubString verb (*scs:...) when used in conjunction with the (*ACCEPT) directive.
When processing these specific pattern constructs, the matching engine fails to properly restore the buffer boundaries after an ACCEPT operation occurs inside a scan substring block. This causes the engine to operate with incorrect buffer bounds, leading to an out-of-bounds read during subsequent memcmp operations. The network-accessible attack vector means malicious patterns could potentially be submitted remotely to vulnerable applications that accept user-provided regular expressions.
Root Cause
The root cause of this vulnerability lies in improper state management within the pcre2_match.c source file. Specifically, when an (*ACCEPT) operation is executed inside a Scan SubString block, the saved buffer boundaries (end_subject, true_end_subject, and moptions) are not properly restored before continuing execution. This leaves the matching engine operating with stale buffer boundaries from the substring context, causing it to read beyond the intended buffer limits during subsequent memory comparison operations.
Attack Vector
An attacker can exploit this vulnerability by crafting a malicious regular expression pattern that combines the (*scs:...) verb with (*ACCEPT) in a specific sequence. When a vulnerable application processes this pattern, the heap-buffer-overflow read occurs. If the out-of-bounds data influences the matching result in an observable manner, the attacker may be able to infer information about adjacent heap memory contents, potentially leading to information disclosure.
The attack requires the ability to supply regular expression patterns to an application using PCRE2 10.45. This could be achieved through web application input fields, API endpoints, configuration files, or any other mechanism that allows user-controlled regex patterns.
// Security patch from src/pcre2_match.c - Restore buffer after an ACCEPT inside a scan substring block
assert_accept_frame->offset_top * sizeof(PCRE2_SIZE));
Foffset_top = assert_accept_frame->offset_top;
Fmark = assert_accept_frame->mark;
+ mb->end_subject = Lsaved_end_subject;
+ mb->true_end_subject = mb->end_subject + Ltrue_end_extra;
+ mb->moptions = Lsaved_moptions;
break;
}
Source: GitHub Commit a141712e
Detection Methods for CVE-2025-58050
Indicators of Compromise
- Unusual application crashes or memory access violations in processes using PCRE2
- Regex-related error logs indicating unexpected pattern matching behavior
- Memory corruption patterns detected in heap regions adjacent to PCRE2 allocations
- Anomalous regex patterns containing (*scs:...) combined with (*ACCEPT) constructs
Detection Strategies
- Monitor for applications using PCRE2 version 10.45 through software inventory scanning
- Implement input validation to detect and filter suspicious regex patterns containing (*scs: and (*ACCEPT) combinations
- Deploy memory sanitizers (AddressSanitizer, Valgrind) in development and testing environments to identify heap-buffer-overflow conditions
- Review application logs for regex processing errors that may indicate exploitation attempts
Monitoring Recommendations
- Enable detailed logging for regex pattern processing in applications using PCRE2
- Implement real-time monitoring for memory access violations and heap corruption events
- Set up alerts for unusually complex or lengthy regular expression patterns submitted to applications
- Monitor for applications accessing PCRE2 library functions with unexpected frequency or patterns
How to Mitigate CVE-2025-58050
Immediate Actions Required
- Upgrade PCRE2 to version 10.46 or later immediately
- Identify all applications and dependencies using PCRE2 10.45 through software composition analysis
- Restrict user input of regular expressions where possible until patching is complete
- Implement input validation to reject patterns containing potentially dangerous verb combinations
Patch Information
The PCRE2 development team has released version 10.46 which resolves this vulnerability. The fix properly restores the buffer boundaries (end_subject, true_end_subject, and moptions) after an (*ACCEPT) operation completes inside a Scan SubString block. Organizations should update to PCRE2 10.46 or later as documented in the GitHub Release pcre2-10.46. The specific commit addressing this issue can be reviewed at the GitHub Commit Update. Additional details are available in the GitHub Security Advisory GHSA-c2gv-xgf5-5cc2.
Workarounds
- Implement input filtering to reject regex patterns containing (*scs: substring constructs
- Sandbox applications that process user-supplied regular expressions
- Limit regex pattern complexity and length through application-level validation
- Consider temporarily disabling features that allow user-defined regular expressions until patching is complete
# Check current PCRE2 version
pcre2-config --version
# Update PCRE2 on Debian/Ubuntu systems
sudo apt-get update && sudo apt-get install --only-upgrade libpcre2-dev
# Update PCRE2 on RHEL/CentOS systems
sudo yum update pcre2
# Verify update was successful
pcre2-config --version
Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.


