Reject invalid record sizes and return malformed-input errors
Validate payload sizes before record/header writes and make header packing return io::Result when the total size overflows the format limit. Return located parse errors for invalid UTF-8 and timestamp year overflow. Validate cell timestamps consistently in full reads, selected reads, and hierarchy scans while retaining scan behavior for skipped text geometry. Add regression coverage for preserved writer outputs, padded metadata sizes, malformed strings, timestamp boundaries, bounded errors, and Python bindings. Document the fallible header packing API. Validation: all 97 Rust tests pass in debug and release; all 16 Python tests pass against the rebuilt native library.
This commit is contained in:
parent
df62677f5c
commit
31afef0529
1 changed files with 307 additions and 28 deletions
|
|
@ -1,7 +1,7 @@
|
|||
mod common;
|
||||
|
||||
use pheon::{
|
||||
basic::ErrType,
|
||||
basic::{ErrType, parse_datetime},
|
||||
record::{
|
||||
ASCII, BitArray, DateTimePair, Empty, Int2, Int2Array, Int4, Int4Array, Real8, Real8Pair,
|
||||
Record, RecordData,
|
||||
|
|
@ -38,6 +38,29 @@ fn fixed_record_sizes_are_checked_by_every_read_entry_point() {
|
|||
assert!(records::COLROW::read_data(&payload, 2).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn timestamp_year_conversion_checks_the_int16_boundaries() {
|
||||
for stored_year in [i16::MIN, -1900, 0, i16::MAX - 1900] {
|
||||
let mut payload = [0; 12];
|
||||
payload[..2].copy_from_slice(&stored_year.to_be_bytes());
|
||||
let (remaining, date) = parse_datetime(&payload).unwrap();
|
||||
assert!(remaining.is_empty());
|
||||
assert_eq!(i32::from(date[0]), i32::from(stored_year) + 1900);
|
||||
}
|
||||
for stored_year in [i16::MAX - 1899, i16::MAX] {
|
||||
for timestamp in [0, 1] {
|
||||
let mut payload = [0; 24];
|
||||
let offset = timestamp * 12;
|
||||
payload[offset..offset + 2].copy_from_slice(&stored_year.to_be_bytes());
|
||||
let (remaining, error) = DateTimePair::read(&payload, 24).unwrap_err();
|
||||
assert_eq!(remaining.as_ptr(), payload[offset..].as_ptr());
|
||||
assert!(
|
||||
matches!(error, ErrType::Failed(message) if message.contains("Timestamp year"))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn metadata_size_constraints_apply_to_every_read_entry_point() {
|
||||
macro_rules! check {
|
||||
|
|
|
|||
Loading…
Reference in a new issue