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:
Jan Petykiewicz 2026-11-16 21:28:54 -08:00
commit 31afef0529

View file

@ -12,7 +12,7 @@ use crate::records::{
use crate::records;
use crate::record::{RecordHeader, Record};
use crate::basic::{IResult, fail, take_bytes};
use crate::basic::{IResult, decode_utf8, fail, take_bytes};
use std::string::String;
use std::collections::HashMap;
@ -784,7 +784,7 @@ fn read_text<'a>(
xy_builder.append_value(xy);
let (input, string_bytes) = STRING::read(input)?;
let string = String::from_utf8(string_bytes).unwrap();
let string = decode_utf8(string_bytes).map_err(|error| (input, error))?;
let string_builder = text_builder.field_builder::<StringBuilder>(10).unwrap();
string_builder.append_value(string);
@ -856,7 +856,7 @@ fn read_ref<'a>(
let mut colrow = None;
let (input, struct_name_bytes) = SNAME::skip_and_read(input)?;
let struct_name = String::from_utf8(struct_name_bytes).unwrap();
let struct_name = decode_utf8(struct_name_bytes).map_err(|error| (input, error))?;
let next_id = names.len();
let id = names.entry(struct_name).or_insert(next_id.try_into().unwrap());
@ -986,7 +986,7 @@ fn walk_properties<'a>(
on_property(PropertyRecord {
key,
value: String::from_utf8(value_bytes).unwrap(),
value: decode_utf8(value_bytes).map_err(|error| (input, error))?,
});
}
(input, header) = RecordHeader::read(input)?;