Skip to content

Commit 15aa49b

Browse files
authoredMar 12, 2024
Unrolled build for rust-lang#122245
Rollup merge of rust-lang#122245 - saethlin:check-dep-graph-size, r=petrochenkov Detect truncated DepGraph files I suspect that the following issues are caused by truncated incr comp files: * rust-lang#120582 * rust-lang#121499 * rust-lang#122210 We fail with an allocation failure or capacity overflow in this case because we assume that the ending bytes of an DepGraph file are the lengths of arrays. If the file has somehow been truncated then the ending bytes are probably some of our varint encoding, which tries to eliminate zero bytes, so interpreting a random 8 bytes as an array length has a very high chance of producing a byte capacity over `isize::MAX`. Now theoretically since rust-lang#119510 merged I have fixed the out-of-disk issues and yet in rust-lang#120894 (comment) I still see some decoding failures that look like out-of-disk ICEs, for example https://crater-reports.s3.amazonaws.com/beta-1.77-1/beta-2024-02-10/gh/scottfones.aoc_2022/log.txt So this PR should ensure that we get an ICE that clearly identifies if the file in question is truncated.
2 parents 7de1a1f + 11f8866 commit 15aa49b

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)