Finding Likely Errors with Bayesian Specifications

Vijayaraghavan Murali, Swarat Chaudhuri, Chris JermainearXiv 2017

Abstract

Writing formal specifications for software behavior is a labor-intensive process. While automated learning from large code repositories ("Big Code") offers a solution, it is often hampered by noise and the inherent heterogeneity of API usage. This paper introduces SALENTO, a Bayesian framework that learns context-sensitive specifications. By combining Latent Dirichlet Allocation (LDA) for topic modeling with topic-conditioned Recurrent Neural Networks (RNNs), SALENTO identifies bugs as statistical anomalies. Evaluation on 750 Android applications demonstrates that this approach effectively discovers complex, real-world bugs while significantly reducing false positives compared to non-Bayesian models.

Introduction

The proliferation of open-source software provides a massive corpus for learning how programs should behave. However, extracting reliable specifications from this "Big Code" is difficult. First, repositories contain "noise"—buggy code that can mislead learning algorithms. Second, APIs are "heterogeneous"; they are used in diverse ways depending on the application context. A one-size-fits-all model often fails to capture these nuances, leading to high false alarm rates.

The SALENTO Framework

To address these challenges, the authors propose SALENTO, a framework that treats API usage as a statistical inference problem. SALENTO employs a two-stage architecture to specialize its understanding for every program it analyzes.

  1. Topic Modeling: Using Latent Dirichlet Allocation (LDA), the system discovers latent "topics" or specifications within the code. For instance, different topics might represent distinct patterns of using the AlertDialog API, such as using resource IDs versus raw strings.
  2. Topic-Conditioned RNN: A Recurrent Neural Network learns typical sequences of API calls. Unlike standard RNNs, this model is conditioned on the topics identified by the LDA. This allows the model to adjust its expectations based on the specific "topic" of the program under analysis.
The SALENTO workflow: Training on a corpus to learn a joint model, then using inference to compute anomaly scores for new programs.

The system identifies bugs by calculating the Kullback-Leibler (KL) divergence between the actual program behavior and the reference distribution predicted by the model. A high KL-divergence score indicates a significant anomaly, flagging the behavior as a likely bug.

Experimental Evaluation

The researchers evaluated SALENTO using a corpus of 750 Android applications, focusing on complex APIs such as android.app.AlertDialog.Builder, android.bluetooth.BluetoothSocket, and javax.crypto.Cipher. The model was trained on 500 apps and tested on the remaining 250.

Key Results

SALENTO successfully identified 10 distinct types of real-world bugs, ranging from UI glitches to security vulnerabilities. Notable examples include:

  • Unclosable Dialogs: Dialog boxes appearing without buttons, effectively locking the application.
  • Insecure Cryptography: Improper initialization of Cipher objects leading to insecure default modes (e.g., ECB).
  • Resource Leaks: Failure to close Bluetooth sockets during connection failures.
Examples of abnormal dialog boxes and corresponding code snippets found in Android applications.

Quantitatively, the Bayesian approach demonstrated superior stability. In heterogeneous environments, standard RNN models saw error scores increase by up to 3.5x, whereas SALENTO remained robust. At a precision threshold of 75%, the tool achieved an 80% recall rate for known bugs.

Conclusion and Future Work

SALENTO demonstrates the power of Bayesian inference in learning from large-scale, noisy codebases. By specializing specifications to program context, it provides a rigorous method for anomaly-based bug detection. Future work includes addressing the overhead of symbolic execution and scaling the framework to support a wider variety of programming languages and larger codebases.

Summary updated

BibTeX
@misc{murali2017finding,
  author = {Vijayaraghavan Murali and Swarat Chaudhuri and Chris Jermaine},
  title = {{Finding Likely Errors with Bayesian Specifications}},
  year = {2017},
  eprint = {1703.01370},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1703.01370},
}
Figure