-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path0124-rdiff.rs
54 lines (46 loc) · 1.12 KB
/
0124-rdiff.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*!
```rudra-poc
[target]
crate = "rdiff"
version = "0.1.2"
[report]
issue_url = "https://github.com/dyule/rdiff/issues/3"
issue_date = 2021-02-03
rustsec_url = "https://github.com/RustSec/advisory-db/pull/862"
rustsec_id = "RUSTSEC-2021-0094"
[[bugs]]
analyzer = "UnsafeDataflow"
bug_class = "HigherOrderInvariant"
rudra_report_locations = ["src/window.rs:8:5: 27:6"]
```
!*/
#![forbid(unsafe_code)]
use rdiff::BlockHashes;
use std::io::{Cursor, Read};
struct MyRead {
first: bool,
}
impl MyRead {
pub fn new() -> Self {
MyRead { first: false }
}
}
impl Read for MyRead {
fn read(&mut self, _buf: &mut [u8]) -> std::io::Result<usize> {
if !self.first {
self.first = true;
// First iteration: return more than the buffer size
Ok(256)
} else {
// Second iteration: indicate that we are done
Ok(0)
}
}
}
fn main() {
let mut hashes = BlockHashes::new(Cursor::new("Hello"), 32).unwrap();
let diff = hashes.diff_and_update(MyRead::new()).unwrap();
for insert in diff.inserts() {
println!("{:?}", insert);
}
}