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
|
|
@ -19,7 +19,7 @@ fn record_headers_include_their_own_size() {
|
|||
data_size: u16::MAX - 4,
|
||||
tag: 0x1003,
|
||||
};
|
||||
assert_eq!(maximum.pack_into(), [0xff, 0xff, 0x10, 0x03]);
|
||||
assert_eq!(maximum.pack_into().unwrap(), [0xff, 0xff, 0x10, 0x03]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -135,4 +135,58 @@ fn oversized_records_fail_before_writing() {
|
|||
let error = records::XY::write(&mut bytes, &vec![0; 16383]).unwrap_err();
|
||||
assert_eq!(error.kind(), io::ErrorKind::InvalidInput);
|
||||
assert!(bytes.is_empty());
|
||||
|
||||
// Header packing and direct header writes reject every overflowing size too.
|
||||
for data_size in u16::MAX - 3..=u16::MAX {
|
||||
let header = RecordHeader {
|
||||
tag: records::RTAG_XY,
|
||||
data_size,
|
||||
};
|
||||
assert_eq!(
|
||||
header.pack_into().unwrap_err().kind(),
|
||||
io::ErrorKind::InvalidInput
|
||||
);
|
||||
assert_eq!(
|
||||
header.write(&mut bytes).unwrap_err().kind(),
|
||||
io::ErrorKind::InvalidInput
|
||||
);
|
||||
assert!(bytes.is_empty());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_record_sizes_preserve_the_output() {
|
||||
let mut bytes = vec![0xa5];
|
||||
for count in [0, 1, 3] {
|
||||
let error = records::COLROW::write(&mut bytes, &vec![2; count]).unwrap_err();
|
||||
assert_eq!(error.kind(), io::ErrorKind::InvalidInput);
|
||||
assert_eq!(bytes, [0xa5]);
|
||||
}
|
||||
let error = records::COLROW::write_header(&mut bytes, 2).unwrap_err();
|
||||
assert_eq!(error.kind(), io::ErrorKind::InvalidInput);
|
||||
assert_eq!(bytes, [0xa5]);
|
||||
|
||||
macro_rules! check_metadata {
|
||||
($record:ident) => {
|
||||
for count in [43, 44, 45] {
|
||||
let payload = vec![b'x'; count];
|
||||
let mut bytes = vec![0xa5];
|
||||
let result = records::$record::write(&mut bytes, &payload);
|
||||
if count == 45 {
|
||||
assert_eq!(result.unwrap_err().kind(), io::ErrorKind::InvalidInput);
|
||||
assert_eq!(bytes, [0xa5]);
|
||||
} else {
|
||||
// Validation uses the padded record size, not the input length.
|
||||
assert_eq!(result.unwrap(), 48);
|
||||
assert_eq!(records::$record::read(&bytes[1..]).unwrap().1, payload);
|
||||
}
|
||||
}
|
||||
let error = records::$record::write_header(&mut bytes, 46).unwrap_err();
|
||||
assert_eq!(error.kind(), io::ErrorKind::InvalidInput);
|
||||
assert_eq!(bytes, [0xa5]);
|
||||
};
|
||||
}
|
||||
check_metadata!(REFLIBS);
|
||||
check_metadata!(FONTS);
|
||||
check_metadata!(ATTRTABLE);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue