Skip to content

Commit 36d6bf9

Browse files
committed
Restore finite-EOF table bounds for offline profiles
Match CPython's EOF-wide table count and decoding windows while retaining checked offsets, allocation limits, cursor bounds, and replay checks. This restores the original mega's finite-file contract without changing canonical tests or the already validated argument-binding implementation. Assisted-by: OpenAI Codex:model version unavailable
1 parent 0eee27f commit 36d6bf9

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

‎crates/stdlib/src/_remote_debugging/binary.rs‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ impl Reader {
792792
let mut footer = Cursor::new(&data[footer_start..]);
793793
let string_count = endian.u32(footer.fixed()?);
794794
let frame_count = endian.u32(footer.fixed()?);
795-
let (profile_stats, tables_end) = parse_profile_stats(&data, endian, footer_start)?;
795+
let (profile_stats, _) = parse_profile_stats(&data, endian, footer_start)?;
796796
for (name, offset) in [("string", string_offset), ("frame", frame_offset)] {
797797
if offset > data.len() as u64 {
798798
return Err(invalid(format!(
@@ -815,15 +815,14 @@ impl Reader {
815815
.map_err(|_| Error::Overflow("File is too large to read"))?;
816816
let frame_offset = usize::try_from(frame_offset)
817817
.map_err(|_| Error::Overflow("File is too large to read"))?;
818-
if frame_offset > tables_end {
819-
return Err(invalid("Frame table overlaps file trailer"));
820-
}
821818
if compression_type == 1 {
822819
return Err(Error::Runtime(
823820
"File uses zstd compression but zstd support not compiled in",
824821
));
825822
}
826-
let mut string_data = Cursor::new(&data[string_offset..frame_offset]);
823+
// CPython bounds table entries by the remaining file bytes, including
824+
// subsequent sections. Keep the count and cursor checks anchored to EOF.
825+
let mut string_data = Cursor::new(&data[string_offset..]);
827826
validate_count("string", string_count, string_data.remaining(), 1)?;
828827
let mut strings = Vec::new();
829828
reserve(&mut strings, string_count as usize)?;
@@ -836,7 +835,7 @@ impl Reader {
836835
.map_err(|_| invalid("String table overflow"))?;
837836
strings.push(decode_utf8_replacing(bytes)?);
838837
}
839-
let mut frame_data = Cursor::new(&data[frame_offset..tables_end]);
838+
let mut frame_data = Cursor::new(&data[frame_offset..]);
840839
validate_count("frame", frame_count, frame_data.remaining(), 7)?;
841840
let mut frames = Vec::new();
842841
reserve(&mut frames, frame_count as usize)?;

0 commit comments

Comments
 (0)