Skip to content

Commit 02f7742

Browse files
committed
Fix soundness hole in Ref::into_ref and into_mut (#721)
This commit implements the fix for #716 which will be released as a new version in version trains 0.2, 0.3, 0.4, 0.5, 0.6, and 0.7. See #716 for a description of the soundness hole and an explanation of why this fix is chosen. Unfortunately, due to dtolnay/trybuild#241, there is no way for us to write a UI test that will detect a failure post-monomorphization, which is when the code implemented in this change is designed to fail. I have manually verified that unsound uses of these APIs now fail to compile. Release 0.5.2.
1 parent cfb2a95 commit 02f7742

File tree

5 files changed

+373
-82
lines changed

5 files changed

+373
-82
lines changed

Cargo.toml.crates-io renamed to Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
[package]
88
edition = "2018"
99
name = "zerocopy"
10-
version = "0.5.1"
10+
version = "0.5.2"
1111
authors = ["Joshua Liebow-Feeser <joshlf@google.com>"]
1212
description = "Utilities for zero-copy parsing and serialization"
1313
license = "BSD-3-Clause"

src/byteorder.rs

Lines changed: 72 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,42 @@ define_type!(
311311
[u32, u64, u128, usize],
312312
[U32, U64, U128]
313313
);
314-
define_type!(A, U32, u32, 32, 4, read_u32, write_u32, unsigned, [u64, u128], [U64, U128]);
315-
define_type!(A, U64, u64, 64, 8, read_u64, write_u64, unsigned, [u128], [U128]);
316-
define_type!(A, U128, u128, 128, 16, read_u128, write_u128, unsigned, [], []);
314+
define_type!(
315+
A,
316+
U32,
317+
u32,
318+
32,
319+
4,
320+
read_u32,
321+
write_u32,
322+
unsigned,
323+
[u64, u128],
324+
[U64, U128]
325+
);
326+
define_type!(
327+
A,
328+
U64,
329+
u64,
330+
64,
331+
8,
332+
read_u64,
333+
write_u64,
334+
unsigned,
335+
[u128],
336+
[U128]
337+
);
338+
define_type!(
339+
A,
340+
U128,
341+
u128,
342+
128,
343+
16,
344+
read_u128,
345+
write_u128,
346+
unsigned,
347+
[],
348+
[]
349+
);
317350
define_type!(
318351
An,
319352
I16,
@@ -326,9 +359,42 @@ define_type!(
326359
[i32, i64, i128, isize],
327360
[I32, I64, I128]
328361
);
329-
define_type!(An, I32, i32, 32, 4, read_i32, write_i32, signed, [i64, i128], [I64, I128]);
330-
define_type!(An, I64, i64, 64, 8, read_i64, write_i64, signed, [i128], [I128]);
331-
define_type!(An, I128, i128, 128, 16, read_i128, write_i128, signed, [], []);
362+
define_type!(
363+
An,
364+
I32,
365+
i32,
366+
32,
367+
4,
368+
read_i32,
369+
write_i32,
370+
signed,
371+
[i64, i128],
372+
[I64, I128]
373+
);
374+
define_type!(
375+
An,
376+
I64,
377+
i64,
378+
64,
379+
8,
380+
read_i64,
381+
write_i64,
382+
signed,
383+
[i128],
384+
[I128]
385+
);
386+
define_type!(
387+
An,
388+
I128,
389+
i128,
390+
128,
391+
16,
392+
read_i128,
393+
write_i128,
394+
signed,
395+
[],
396+
[]
397+
);
332398

333399
#[cfg(test)]
334400
mod tests {

0 commit comments

Comments
 (0)