Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Subtraction with underflow on empty FixedSizeBinaryArray #20109

Conversation

DzenanJupic
Copy link
Contributor

When trying to deserialize an arrow IPC stream with a fixed-size binary array that contains no values, the code currently subtracts with underflow. In the Python package (which uses a release build), this is silently ignored as debug assertions are turned off. Instead, you get a panic about an out-of-bounds offset.
PanicException: assertion failed: self.check_bound(offset)

By checking for an underflow, everything works fine.

To reproduce the issue, you can try the following code:

// [dependencies]
// arrow = "53.3.0"
// polars = { version = "1.16.0", features = ["polars-io", "ipc", "ipc_streaming"] }

use std::sync::Arc;
use arrow::{datatypes::{DataType, Field, Schema}, record_batch::RecordBatch};
use polars::io::{SerReader, ipc::IpcStreamReader};

fn main() {
    let mut buffer = Vec::new();

    let field = Field::new("bin", DataType::FixedSizeBinary(42), false);
    let schema = Arc::new(Schema::new(vec![field]));

    let column = Arc::new(arrow::array::FixedSizeBinaryBuilder::new(42).finish()) as _;
    let batch = RecordBatch::try_new(schema.clone(), vec![column]).unwrap();

    let mut writer = arrow::ipc::writer::StreamWriter::try_new(&mut buffer, &schema).unwrap();
    writer.write(&batch).unwrap();
    writer.finish().unwrap();

    let _ = IpcStreamReader::new(std::io::Cursor::new(&buffer[..]))
        .finish()
        .unwrap();
}

@DzenanJupic DzenanJupic changed the title Fix subtraction with underflow on empty FixedSizeBinaryArray fix: subtraction with underflow on empty FixedSizeBinaryArray Dec 2, 2024
Copy link

codecov bot commented Dec 2, 2024

Codecov Report

Attention: Patch coverage is 42.85714% with 4 lines in your changes missing coverage. Please review.

Project coverage is 79.53%. Comparing base (58f763a) to head (a67f70c).
Report is 13 commits behind head on main.

Files with missing lines Patch % Lines
crates/polars-compute/src/cast/binary_to.rs 42.85% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #20109      +/-   ##
==========================================
- Coverage   79.53%   79.53%   -0.01%     
==========================================
  Files        1563     1563              
  Lines      217115   217116       +1     
  Branches     2464     2464              
==========================================
- Hits       172679   172677       -2     
- Misses      43876    43879       +3     
  Partials      560      560              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

When trying to deserialize an arrow ipc stream with a fixed size binary
array that contains no values, the code currently subtracts with
underflow. In the python package (which uses a release build), this is
silently ignored as debug assertions are turned off. Instead, you get a
panic about an out of bounds offset.

By checking for an underflow, everythning work fine.
@ritchie46 ritchie46 changed the title fix: subtraction with underflow on empty FixedSizeBinaryArray fix: Subtraction with underflow on empty FixedSizeBinaryArray Dec 3, 2024
@ritchie46 ritchie46 merged commit 6254203 into pola-rs:main Dec 3, 2024
20 of 22 checks passed
@github-actions github-actions bot added fix Bug fix python Related to Python Polars rust Related to Rust Polars and removed title needs formatting labels Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Bug fix python Related to Python Polars rust Related to Rust Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants