Skip to content

Commit 11f8866

Browse files
committed
Detect truncated incr comp files
1 parent 4282576 commit 11f8866

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

compiler/rustc_query_system/src/dep_graph/serialized.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,15 @@ impl SerializedDepGraph {
179179
pub fn decode<D: Deps>(d: &mut MemDecoder<'_>) -> SerializedDepGraph {
180180
// The last 16 bytes are the node count and edge count.
181181
debug!("position: {:?}", d.position());
182-
let (node_count, edge_count) =
183-
d.with_position(d.len() - 2 * IntEncodedWithFixedSize::ENCODED_SIZE, |d| {
182+
let (node_count, edge_count, graph_size) =
183+
d.with_position(d.len() - 3 * IntEncodedWithFixedSize::ENCODED_SIZE, |d| {
184184
debug!("position: {:?}", d.position());
185185
let node_count = IntEncodedWithFixedSize::decode(d).0 as usize;
186186
let edge_count = IntEncodedWithFixedSize::decode(d).0 as usize;
187-
(node_count, edge_count)
187+
let graph_size = IntEncodedWithFixedSize::decode(d).0 as usize;
188+
(node_count, edge_count, graph_size)
188189
});
190+
assert_eq!(d.len(), graph_size);
189191
debug!("position: {:?}", d.position());
190192

191193
debug!(?node_count, ?edge_count);
@@ -491,6 +493,8 @@ impl<D: Deps> EncoderState<D> {
491493
debug!("position: {:?}", encoder.position());
492494
IntEncodedWithFixedSize(node_count).encode(&mut encoder);
493495
IntEncodedWithFixedSize(edge_count).encode(&mut encoder);
496+
let graph_size = encoder.position() + IntEncodedWithFixedSize::ENCODED_SIZE;
497+
IntEncodedWithFixedSize(graph_size as u64).encode(&mut encoder);
494498
debug!("position: {:?}", encoder.position());
495499
// Drop the encoder so that nothing is written after the counts.
496500
let result = encoder.finish();

0 commit comments

Comments
 (0)