PanicKiller

This website provides supplementary materials for the paper "Towards Fixing Panic Bugs for Real-world Rust Programs".

Abstract

The Rust programming language has garnered significant attention due to its robust safety features and memory management capabilities. Despite its guaranteed memory safety, Rust programs still suffer from runtime errors that are unmanageable, i.e., panic errors. Notably, over half of the bugs in rustc, Rust’s own compiler, are attributable to crash errors stemming from panic errors. However, understanding the root causes and resolving these panics often requires substantial effort due to the limited information provided, and the stack backtrace could be intricate, often omitting the actual fault locations. Although numerous automated program repair techniques exist, we have observed that the prevailing fix patterns do not readily apply to Rust programs due to natural differences in language mechanisms.

To tackle the above challenges, this paper introduces a systematic study aimed at fixing Rust panic bugs. We commence by assembling a dataset, namely Panic4R, of real panic bugs and their corresponding fixes from the top 100 downloaded open-source crates. Utilizing this dataset, we then identify common patterns in panic bug resolution, which could guide the understanding and pattern-based rectification of such issues. Finally, we design and implement the first automated fixing tool PanicKiller for Rust panic bugs, which effectively generates correct patches on the real-world large-scale dataset, and has already assisted in the resolution of four panic bugs in open-source crates. All resolved issues have been validated by the developers and merged into the respective codebases.


Here, we provide more details on Fix Pattern Mining, including more fix patterns PanicKiller uses. 

Error Handling

1. Insert Match Unwrapper

Template Description

When unwrapping on [value], add or revise match arms to [variable] after unwrapping to handle all possible circumstances to avoid panics caused by unwrapping on None/Invalid values.

Related PRs

2. Mutate Error Handler

Template Description

Replace the [original handler] with [new handler] to avoid panics caused by incorrect error handling like [original handler].

Related PRs

Binary Operation

1. Mutate Binary Operator

Template Description

Replace basic arithmetic operations [operator] with safer operations [call name] to handle arithmetic [operator] overflow panics. Note that [explanation].

Related PRs

2. Mutate Binary Call

Template Description

Replace basic arithmetic operations [binary call] with safer operations [call name] to handle arithmetic [operator] overflow panics. Note that [explanation].

Related PRs

3. Insert Zero-Checker

Template Description

Insert a zero checker to check whether [variable] is zero when divided/moded to avoid the panics caused by division by zero.

Related PRs

4. Mutate Division-by-zero

Template Description

Modify a division-by-zero expression by incorporating max(1) to constrain the divisor [variable], thereby preventing panics resulting from division by zero.

Related PRs

5. Mutate Binary Expression

Template Description

Mutate a binary expression.  

Related PRs

Index and Range Expression

1. Insert Range Checker

Template Description

Implement range checking for the [index] of indices [array name] to determine whether [condition], avoiding panics caused by index out of bounds or exceed the boundary.

Related PRs

2. Mutate Index Expression

Template Description

Mutate [index] in indices [array name], avoiding panics caused by index out of bounds or exceed the boundary.

Related PRs

If/If-let Expression

1. Mutate Condition

Template Description

Adjust conditions within if statements to check whether [condition].

Related PRs

2. Negate Condition

Template Description

Negate conditions within if statements to handle NaN during [condition] check.

Related PRs

Unsafe

1. Insert Unsafe Block

Template Description

Insert an unsafe block when [precondition] is met to change the behaviour of [variable].

Related PRs

Method Call

1. Mutate Method Invocation

Template Description

Replace the original call [call name] with another [new call name] with the same parameters.

Related PRs

2. Insert Call Invocation

Template Description

Add new method call [call name] to [variable].

Related PRs

Closure

1. Mutate Map

Template Description

Change map to filter_map with mutated closure to avoid panics caused by unwrapping on None/Invalid value.

Related PRs

Return

1. Mutate Return

Template Description

Change the return value from [old return] to [new return].

Related PRs