TL;DR
This paper introduces the first string solver that natively supports the complex features of real-world regular expressions (RegEx), such as capturing groups and greedy/lazy matching, which are crucial for analyzing programs that manipulate strings. By developing a novel automaton model called Prioritized Streaming String Transducers (PSST) and a corresponding calculus, they achieve significant performance and precision improvements over existing methods for solving string constraints.
What Problem Does This Paper Address?
Modern programming languages heavily rely on string manipulation, and regular expressions (RegEx) are a ubiquitous tool for pattern matching and text processing. However, the RegEx implementations in languages like JavaScript often go beyond the theoretical definition of regular languages, incorporating features like capturing groups and non-standard greedy/lazy matching semantics. This divergence makes it challenging for existing string solvers, which are typically based on simpler theoretical models, to accurately analyze programs that utilize these advanced RegEx features. This gap leads to imprecision and performance issues in symbolic execution and program analysis, potentially missing bugs or incorrectly reporting them. The authors aim to bridge this gap by providing a string solver that can precisely and efficiently handle these complex RegEx features.
Methods
The core of the paper's contribution lies in two key innovations:
- Prioritized Streaming String Transducers (PSST): This novel automaton model extends traditional streaming string transducers by incorporating transition priorities (to handle greedy/lazy semantics) and string variables (to capture groups). PSSTs are designed to formally capture the semantics of RegEx-dependent string functions like
extract,replace, andreplaceAll. - Propagation-Based Calculus: The authors develop a sound sequent calculus that leverages the properties of PSSTs to solve string constraints. This calculus propagates regular language constraints by computing images and pre-images of string functions. A key insight is that pre-images of regular languages under PSSTs are always regular, which is crucial for maintaining decidability and enabling effective constraint solving. They also introduce a decidable fragment of their string constraint language, the "straight-line" fragment, which includes concatenation, extraction, and replacement.
Datasets
The authors evaluate their approach using two collections of JavaScript programs generated from a library of real-world regular expressions. These benchmarks consist of 98,117 RegExes and are used to create path constraints for testing their solver.
Key Insights and Ideas
- Bridging the Theory-Practice Gap: The paper highlights the significant discrepancy between theoretical regular expressions and their practical implementations in programming languages, emphasizing the need for solvers to handle these real-world nuances.
- PSSTs as a Unified Model: The PSST model elegantly captures both the priority-based semantics of RegEx operators and the capturing of group matches, providing a unified framework for analyzing complex RegEx-dependent functions.
- Pre-image Regularity is Key: The crucial finding that pre-images of regular languages under PSSTs are regular is the cornerstone of their decidable calculus, enabling effective propagation of constraints.
- Native Support Outperforms Approximation: The experimental results strongly suggest that natively supporting RegEx features within a solver, rather than approximating them (as in ExpoSE), leads to substantial gains in both precision and efficiency.
Key Results
- Performance Improvement: OSTRICH, their solver based on PSSTs, significantly outperforms ExpoSE+Z3, achieving an 8x-18x speedup on average for RegEx-related string constraints.
- Increased Coverage: OSTRICH covers substantially more paths than ExpoSE+Z3, demonstrating its superior precision in handling RegExes.
- Decidability for a Fragment: The authors prove the decidability of their string constraint language for the straight-line fragment, providing a complete decision procedure for this important subset.
- Experimental Validation: Extensive experiments on a large benchmark suite confirm that their approach is consistent with JavaScript semantics and is highly competitive.
Limitations and Future Work
- Undecidability in General: The full string constraint language is undecidable, although their approach is complete for the straight-line fragment.
- Backreferences and Lookahead: The current framework does not handle RegEx features like backreferences and lookahead. The authors suggest exploring alternating automata for lookahead and higher-order automata for backreferences, acknowledging the potential complexity and undecidability challenges.
- Integration with Symbolic Execution: While they integrated OSTRICH with the Aratha symbolic execution tool, they suggest further work on combining their solver with tools like ExpoSE to create a full symbolic execution engine.
- Other Data Types: The authors note the need to extend their work to handle other data types, such as integers, to better model real-world programs.
Summary updated