Potential soundness issue in `bitpacking` 0.9.3

Đang mở
#70 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
72/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
rust
Lĩnh vực
security

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Rust
Star
346
Fork
37
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của quickwit-oss/bitpacking

Tất cả issue của quickwit-oss/bitpacking

Issue tương tự

Thêm issue về Rust

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.