Skip to content

Julian-Rederle/bsdiff6

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bsdiff6

bsdiff6[3] is a Rust implementation of the successor to the well-known and commonly used bsdiff4[4].

The implementation is faithful to the original (unpublished) bsdiff6 prototype by Colin Percival.

bsdiff6 was designed to produce roughly 20% smaller patches than bsdiff4[1]. Our research shows that, compared to the most recently available version of bsdiff4[4], bsdiff6 provides an improvement of around 5%[5].

This project also provides a reimplementation of bsdiff4 in Rust that produces patches closer to the original implementation[4] compared to other implementations such as bsdiff-rs and bidiff.

Usage

bsdiff6 (and bsdiff4) are available both as a library and as a command-line tool.

Prerequisites:

  • Rust toolchain (rustup + cargo)
  • A recent Rust stable (1.60+ recommended)

Build the whole workspace (library + CLI):

# from repository root
cargo build --workspace --release

Library

Add this workspace as a dependency (or reference path in Cargo.toml), then:

use bsdiff::diff::{bsdiff4, bsdiff6};

...

    let old: Vec<u8> = std::fs::read("old.bin").unwrap();
    let new: Vec<u8> = std::fs::read("new.bin").unwrap();

    let alignments_v4 = bsdiff4(&old, &new);
    let alignments_v6 = bsdiff6(&old, &new);

    // Alternatively use custom logic here
    let package_result = patch_packer::package(alignment, &old_buffer, &new_buffer, verbose);
    let compressed_patch: Vec<u8> = package_result.unwrap();

    ...

CLI

Diff two files (produce compressed patch):

bsdiff-cli diff old.bin new.bin -o patch.diff

Default mode is bsdiff6; use -m bsdiff4 to use the classic bsdiff4 implementation.

Patch (apply patch to old file):

bsdiff-cli patch old.bin patch.diff new_out.bin

License

Copyright 2003-2006 Colin Percival
Copyright 2026 Julian Rederlechner
Copyright 2026 CISPA Helmholtz Center for Information Security

This project is governed by the Apache License 2.0. For details see the file titled LICENSE in the project root folder.

Citations

[1] https://www.daemonology.net/bsdiff/
[2] Colin Percival, Naive differences of executable code, http://www.daemonology.net/bsdiff/, 2003
[3] Colin Percival, Matching with Mismatches and Assorted Applications, https://www.daemonology.net/papers/thesis.pdf, 2006
[4] https://github.com/cperciva/bsdiff
[5] Julian Rederlechner, One small patch for a file, one giant leap for ota updates, http://www.daemonology.net/bsdiff/, 2026\

Notes and Disclaimer

  • We are aware that, in rare cases, too many longest matching suffix lookups in the sacapart Rust crate used in this code can cause runtime issues. This problem appears to occur only when using bsdiff6.
  • This is research-grade code, not production-grade code.
  • I had never touched Rust before this project.

About

bsdiff6 is a Rust implementation of the successor to the well-known and commonly used bsdiff4.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages