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
21
src/basic.rs
21
src/basic.rs
|
|
@ -79,12 +79,23 @@ pub fn parse_real8(input: &[u8]) -> IResult<'_, f64> {
|
|||
|
||||
pub fn parse_datetime(input: &[u8]) -> IResult<'_, [i16; 6]> {
|
||||
let mut buf = [0_i16; 6];
|
||||
let mut input = input;
|
||||
for bb in &mut buf {
|
||||
(input, *bb) = parse_int2(input)?;
|
||||
let (mut remaining, year) = parse_int2(input)?;
|
||||
let Some(year) = year.checked_add(1900) else {
|
||||
return fail(
|
||||
input,
|
||||
"Timestamp year exceeds the Int16 range after adding 1900".to_string(),
|
||||
);
|
||||
};
|
||||
buf[0] = year;
|
||||
for bb in &mut buf[1..] {
|
||||
(remaining, *bb) = parse_int2(remaining)?;
|
||||
}
|
||||
buf[0] += 1900; // Year is from 1900
|
||||
Ok((input, buf))
|
||||
Ok((remaining, buf))
|
||||
}
|
||||
|
||||
pub(crate) fn decode_utf8(bytes: Vec<u8>) -> Result<String, ErrType> {
|
||||
String::from_utf8(bytes)
|
||||
.map_err(|error| ErrType::Failed(format!("Invalid UTF-8 string: {}", error.utf8_error())))
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue