Potential soundness issue in `bitpacking` 0.9.3

Aperta
#70 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Tranquilla
Stack tecnologico
rust
Ambito
security

Direzione di ricerca

Start with the safe wrappers in src/bitpacker1x.rs:161 and the unsafe implementation in src/macros_simple.rs:424-438. Run the provided short-slice reproducer under Miri, then inspect the corresponding sorted variants. Done means the public sorted APIs reject invalid block lengths or otherwise avoid undefined behavior, with the reproducer no longer reporting the dangling-pointer access.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Hello, and thank you for maintaining this crate.

I found a sanitizer/Miri failure reachable through public crate APIs using safe Rust code. I may be missing crate-specific preconditions, but the behavior looks worth checking because safe callers should not be able to trigger undefined behavior.

Summary

  • Crate: bitpacking
  • Version tested: 0.9.3
  • API paths with similar failures observed:
    • BitPacker1x::num_bits_sorted
    • BitPacker1x::num_bits_strictly_sorted
    • BitPacker4x::num_bits_sorted
    • BitPacker4x::num_bits_strictly_sorted

Observed diagnostics

Miri undefined behavior: error: Undefined Behavior: memory access failed: attempting to access 4 bytes, but got 0x4[noalloc] which is a dangling pointer (it has no provenance)

Reproduction

The snippets below are minimal readable reproducers. Each PoC also includes the source location most relevant to the reported failure.

PoC 1: test_bitpacking3::generated_test_3

Relevant source location:

  • src/bitpacker1x.rs:161: the safe wrapper calls UnsafeBitPackerImpl::num_bits_sorted.
  • src/macros_simple.rs:424-438: the unsafe implementation loads a full fixed block from decompressed.

Readable equivalent PoC:

use bitpacking::{BitPacker, BitPacker1x};

#[test]
fn poc() {
    let packer = BitPacker1x::new();
    let short_block: Vec<u32> = Vec::new();

    let _ = packer.num_bits_sorted(0, &short_block);
}

Observed diagnostic:

error: Undefined Behavior: memory access failed: attempting to access 4 bytes, but got 0x4[noalloc] which is a dangling pointer (it has no provenance)

Source review and suggested fix

Brief reasoning:

  • The public num_bits path already checks for the exact block length.
  • The sorted variants skip that check and still load a full block from the slice.
  • That makes the length precondition caller-visible through a safe API.

Suggested fix:

  • Validate the exact block length before calling the unsafe routine, or make the precondition explicit in an unsafe API.

Thanks again for taking a look.

Lingua principale
Rust
Stelle
346
Fork
37
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di quickwit-oss/bitpacking

Tutte le issue di quickwit-oss/bitpacking

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.