NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Harnessing LLMs for Document-Guided Fuzzing of OpenCV Library

Bin Duan, Tarek Mahmud, Meiru Che, Yan Yan, Naipeng Dong, Dan Dongseong Kim, Guowei Yang · DOI

Abstract

OpenCV serves as the foundational library for modern computer vision, yet its complexity and documentation inconsistencies pose significant challenges for automated software testing. Traditional fuzzing techniques often struggle with the intricate parameter dependencies and sparse documentation characteristic of such large-scale libraries. This paper introduces VISTAFUZZ, a novel automated testing framework that leverages Large Language Models (LLMs), specifically GPT-4, to interpret documentation and generate intelligent test cases. By extracting structured constraints and inferring missing information through cross-API knowledge transfer, VISTAFUZZ achieved a 99.39% test case validity rate and discovered 17 previously unknown bugs in OpenCV-python v4.9.0, significantly outperforming existing state-of-the-art document-guided fuzzers.

1. Introduction

Computer vision applications, ranging from autonomous driving to medical imaging, rely heavily on the OpenCV library. Given its critical role, ensuring the reliability and robustness of OpenCV is paramount. However, the library's vast API surface and the complex nature of its inputs make traditional fuzzing—which typically relies on random data generation—ineffective. Most randomly generated inputs are rejected by the library's initial validation logic because they fail to respect semantic constraints or inter-parameter dependencies. Furthermore, the quality of OpenCV's documentation varies significantly, leaving many APIs "untestable" by automated tools that require precise specifications.

2. The Challenges of OpenCV Testing

Testing OpenCV presents two primary hurdles:

  1. Complex Semantic Dependencies: Parameters in OpenCV functions are rarely independent. For instance, coordinate inputs must align with the dimensions of the input image. If a fuzzer generates a coordinate outside the image boundary, the function will return an error immediately, preventing the fuzzer from exploring deeper logic.
  2. Documentation Gaps: While some APIs are extensively documented, many others provide only a function signature or incomplete descriptions. Existing document-guided fuzzers typically ignore these poorly documented functions, creating a "blind spot" in the testing process.

3. Methodology: The VISTAFUZZ Framework

VISTAFUZZ addresses these challenges by using GPT-4 to bridge the gap between human-readable documentation and machine-executable test constraints. The framework operates through four key stages:

3.1 Standardization via GPT-4

The system utilizes GPT-4 to parse raw, unstructured documentation into a standardized format. Each parameter is mapped to five specific attributes: Flag (mutability), Default Value, Type, Size, and Description. This structured representation allows the fuzzer to understand the basic requirements of each API.

3.2 Knowledge Transfer for Sparse Documentation

A core innovation of VISTAFUZZ is its ability to handle "poorly-documented" APIs. By treating the library's documentation as a cohesive knowledge base, the LLM can infer constraints for an undocumented parameter by observing how parameters with similar names or roles are defined in well-documented sections of the library. This "documentation repair" capability allows VISTAFUZZ to generate valid tests for functions that were previously inaccessible to automated tools.

3.3 Constraint and Dependency Extraction

Beyond individual parameter types, VISTAFUZZ explicitly identifies relationships between parameters. For example, it can recognize that "Parameter B must have the same height and width as Parameter A." By respecting these dependencies, the framework ensures that generated test cases pass initial validation and reach the core logic of the function.

3.4 Fuzzing Strategies

Once constraints are established, VISTAFUZZ employs three distinct mutation strategies to stress-test the APIs:

  • Type Mutation: Testing both valid and invalid data types.
  • Size Mutation: Probing boundary conditions with extremely large or small dimensions.
  • Value Mutation: Simulating real-world "dirty" data by applying Gaussian noise, random masking, or pixel value manipulation.

4. Experimental Evaluation

The authors evaluated VISTAFUZZ on OpenCV-python (v4.9.0), focusing on a subset of 330 APIs (298 well-documented and 32 poorly-documented). The performance was compared against DocTer, the previous state-of-the-art document-guided fuzzer.

4.1 Bug Detection and Validity

VISTAFUZZ discovered 17 new bugs, including three system crashes, one NaN (Not a Number) value error, and 13 unexpected exceptions. At the time of writing, 10 of these bugs have been confirmed by OpenCV developers, and five have been patched. In contrast, DocTer identified only three bugs.

Crucially, VISTAFUZZ maintained a 99.39% success rate in generating valid test cases. DocTer’s success rate was only 8.74%, illustrating that without understanding complex dependencies, most generated tests are functionally useless.

4.2 Code Coverage

The intelligent constraint extraction of VISTAFUZZ led to a significant increase in code exploration. The framework achieved a line coverage of 48,902, nearly six times higher than the 7,829 lines covered by DocTer.

5. Discussion and Key Insights

The study revealed a strong correlation between documentation quality and software reliability. Although poorly documented APIs made up only 10% of the test set, they accounted for nearly 30% of the detected bugs. This suggests that the lack of clear documentation often mirrors a lack of rigorous internal testing or edge-case handling during development.

6. Limitations and Future Work

Despite its success, VISTAFUZZ cannot yet address the 248 APIs in OpenCV that lack any documentation whatsoever. Future iterations may incorporate static code analysis to derive constraints directly from the source code. Additionally, while GPT-4 proved highly effective, the framework's performance is tied to the capabilities of the underlying LLM. Future research will also explore "sequence fuzzing," where the tool generates sequences of API calls to identify state-related bugs that occur across multiple function executions.

7. Conclusion

VISTAFUZZ demonstrates that LLMs can significantly enhance software testing by transforming ambiguous documentation into precise execution constraints. By achieving high validity and superior code coverage, the framework provides a scalable solution for securing complex, dependency-heavy libraries like OpenCV.

Summary updated

BibTeX
@inproceedings{duan2025harnessing,
  author = {Bin Duan and Tarek Mahmud and Meiru Che and Yan Yan and Naipeng Dong and Dan Dongseong Kim and Guowei Yang},
  title = {{Harnessing LLMs for Document-Guided Fuzzing of OpenCV Library}},
  booktitle = {ICSME},
  year = {2025},
  doi = {10.1109/icsme64153.2025.00017},
}
Figure