Abstract
Deep Learning (DL) libraries like PyTorch and TensorFlow are foundational to modern AI, yet their complexity makes them notoriously difficult to secure and debug. Traditional fuzzing techniques often fail to penetrate deep logic due to the high dimensionality of tensor inputs and the vast API surface area. This paper introduces DFUZZ, a novel "white-box" fuzzing framework that leverages Large Language Models (LLMs) to extract edge-case knowledge directly from library source code. By identifying internal error-checking patterns and transferring this knowledge across thousands of APIs, DFUZZ uncovered 37 previously unknown bugs in major frameworks while requiring significantly fewer computational resources than existing state-of-the-art tools.
1. Introduction
As Deep Learning (DL) libraries become the bedrock of critical infrastructure, ensuring their reliability is paramount. However, testing these libraries is a monumental challenge. With over 1,000 APIs in PyTorch and TensorFlow respectively, many of which handle complex, multi-dimensional data structures, traditional random testing (fuzzing) often results in shallow coverage. Most generated inputs fail basic type checks before reaching the core logic of the library.
Existing LLM-based fuzzers have attempted to bridge this gap, but they typically treat libraries as "black boxes," relying on historical bug reports or simple mutations. This approach overlooks a wealth of information hidden within the library's own source code: the internal checks developers implement to prevent crashes. DFUZZ shifts this paradigm by adopting a "white-box" approach, treating developer-defined error checks as a roadmap for potential exploits.
2. The DFUZZ Framework
DFUZZ operates through a three-stage pipeline designed to maximize API coverage and edge-case discovery.
2.1 Edge Case Extraction
Instead of guessing what might break an API, DFUZZ analyzes the C++ source code of the library (e.g., PyTorch’s ATen core). It uses an LLM to identify internal error-checking macros, such as TORCH_CHECK, which explicitly define unsupported inputs. For instance, if a check specifies that "In-place abs is not supported for complex tensors," DFUZZ extracts a generalized rule: Input should not be a complex tensor. This transforms internal developer knowledge into actionable testing constraints.
2.2 Trial-and-Fix Program Generation
Generating valid test scripts for complex APIs is difficult for LLMs in a single pass. DFUZZ employs a "Trial-and-Fix" loop to synthesize executable Python scripts. If an initial script fails to run, the error message is fed back into the LLM, which iteratively debugs the code until it successfully invokes the target API. This ensures that the fuzzer starts with a stable, valid baseline before attempting to trigger bugs.
2.3 Knowledge Transfer and Mutation
Once a working script is established, DFUZZ applies the extracted edge cases to mutate the inputs. A key innovation of DFUZZ is knowledge transferability. Edge cases are often tied to data types (e.g., empty tensors, specific dtypes) rather than specific API logic. DFUZZ applies rules discovered in one API to thousands of others, even across different frameworks—for example, using PyTorch-derived edge cases to test TensorFlow APIs.
3. Evaluation and Results
3.1 Bug Discovery
DFUZZ was evaluated against the latest versions of PyTorch and TensorFlow. The framework discovered 37 previously unknown bugs, 24 of which were "long-standing" bugs that had persisted through multiple versions and previous fuzzing efforts. At the time of publication, 8 bugs have been officially fixed and 19 have been replicated by library maintainers.
3.2 Efficiency and Coverage
Compared to state-of-the-art (SOTA) tools like TitanFuzz, DFUZZ demonstrated superior efficiency and breadth:
- API Coverage: In PyTorch v1.12, DFUZZ covered 1,455 APIs, outperforming TitanFuzz’s 1,329.
- Resource Efficiency: DFUZZ achieved its results using only 7.12% to 16.81% of the LLM queries required by TitanFuzz, significantly reducing the cost and time of the fuzzing process.
4. Discussion
The core philosophy of DFUZZ—"Your Fix is My Exploit"—highlights a critical oversight in library development: internal error checks are often applied inconsistently. A check added to one API to prevent a crash likely indicates a vulnerability that exists in other, similar APIs where the check is missing. By automating the extraction and transfer of this knowledge, DFUZZ provides a scalable way to harden DL libraries.
4.1 Limitations and Future Work
While highly effective, DFUZZ faces challenges with brand-new APIs that fall outside an LLM's training data. Additionally, while it excels at single-variable edge cases, extracting complex multi-variable constraints (e.g., specific dimensional relationships between two tensors) remains a challenge. Future iterations may incorporate API documentation and user comments to further refine the LLM’s reasoning and script generation capabilities.
5. Conclusion
DFUZZ demonstrates that LLMs can do more than just generate code; they can act as sophisticated "white-box" analysts. By leveraging the internal logic of DL libraries, DFUZZ uncovers deep-seated bugs that black-box methods miss, providing a more comprehensive and efficient path toward secure AI infrastructure.
Summary updated