#198 Reject trailing bytes

Merged Zoey Riordan ZoeyR

No flags found

Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.

e.g., #unittest #integration

#production #enterprise

#frontend #backend

Learn more about Codecov Flags here.


@@ -26,7 +26,7 @@
Loading
26 26
/// let bytes_read = d.bytes_read();
27 27
/// ```
28 28
pub struct Deserializer<R, O: Options> {
29 -
    reader: R,
29 +
    pub(crate) reader: R,
30 30
    options: O,
31 31
}
32 32

@@ -49,20 +49,23 @@
Loading
49 49
            (Unlimited, Little) => {
50 50
                let $opts = DefaultOptions::new()
51 51
                    .with_fixint_encoding()
52 +
                    .allow_trailing_bytes()
52 53
                    .with_no_limit()
53 54
                    .with_little_endian();
54 55
                $call
55 56
            }
56 57
            (Unlimited, Big) => {
57 58
                let $opts = DefaultOptions::new()
58 59
                    .with_fixint_encoding()
60 +
                    .allow_trailing_bytes()
59 61
                    .with_no_limit()
60 62
                    .with_big_endian();
61 63
                $call
62 64
            }
63 65
            (Unlimited, Native) => {
64 66
                let $opts = DefaultOptions::new()
65 67
                    .with_fixint_encoding()
68 +
                    .allow_trailing_bytes()
66 69
                    .with_no_limit()
67 70
                    .with_native_endian();
68 71
                $call
@@ -71,20 +74,23 @@
Loading
71 74
            (Limited(l), Little) => {
72 75
                let $opts = DefaultOptions::new()
73 76
                    .with_fixint_encoding()
77 +
                    .allow_trailing_bytes()
74 78
                    .with_limit(l)
75 79
                    .with_little_endian();
76 80
                $call
77 81
            }
78 82
            (Limited(l), Big) => {
79 83
                let $opts = DefaultOptions::new()
80 84
                    .with_fixint_encoding()
85 +
                    .allow_trailing_bytes()
81 86
                    .with_limit(l)
82 87
                    .with_big_endian();
83 88
                $call
84 89
            }
85 90
            (Limited(l), Native) => {
86 91
                let $opts = DefaultOptions::new()
87 92
                    .with_fixint_encoding()
93 +
                    .allow_trailing_bytes()
88 94
                    .with_limit(l)
89 95
                    .with_native_endian();
90 96
                $call

@@ -52,6 +52,10 @@
Loading
52 52
        self.slice = remaining;
53 53
        Ok(read_slice)
54 54
    }
55 +
56 +
    pub(crate) fn is_finished(&self) -> bool {
57 +
        self.slice.is_empty()
58 +
    }
55 59
}
56 60
57 61
impl<R> IoReader<R> {

@@ -2,7 +2,7 @@
Loading
2 2
use std::io::{Read, Write};
3 3
use std::marker::PhantomData;
4 4
5 -
use config::{Infinite, InternalOptions, Options, SizeLimit};
5 +
use config::{Infinite, InternalOptions, Options, SizeLimit, TrailingBytes};
6 6
use de::read::BincodeRead;
7 7
use Result;
8 8
@@ -111,7 +111,14 @@
Loading
111 111
    T: serde::de::DeserializeSeed<'a>,
112 112
    O: InternalOptions,
113 113
{
114 -
    let reader = ::de::read::SliceReader::new(bytes);
115 114
    let options = ::config::WithOtherLimit::new(options, Infinite);
116 -
    deserialize_from_custom_seed(seed, reader, options)
115 +
116 +
    let reader = ::de::read::SliceReader::new(bytes);
117 +
    let mut deserializer = ::de::Deserializer::with_bincode_read(reader, options);
118 +
    let val = seed.deserialize(&mut deserializer)?;
119 +
120 +
    match O::Trailing::check_end(&deserializer.reader) {
121 +
        Ok(_) => Ok(val),
122 +
        Err(err) => Err(err),
123 +
    }
117 124
}

@@ -94,6 +94,7 @@
Loading
94 94
{
95 95
    DefaultOptions::new()
96 96
        .with_fixint_encoding()
97 +
        .allow_trailing_bytes()
97 98
        .serialize(value)
98 99
}
99 100
@@ -107,6 +108,7 @@
Loading
107 108
{
108 109
    DefaultOptions::new()
109 110
        .with_fixint_encoding()
111 +
        .allow_trailing_bytes()
110 112
        .deserialize_from(reader)
111 113
}
112 114
@@ -122,6 +124,7 @@
Loading
122 124
{
123 125
    DefaultOptions::new()
124 126
        .with_fixint_encoding()
127 +
        .allow_trailing_bytes()
125 128
        .deserialize_from_custom(reader)
126 129
}
127 130
@@ -136,6 +139,7 @@
Loading
136 139
{
137 140
    DefaultOptions::new()
138 141
        .with_fixint_encoding()
142 +
        .allow_trailing_bytes()
139 143
        .deserialize_in_place(reader, place)
140 144
}
141 145
@@ -146,6 +150,7 @@
Loading
146 150
{
147 151
    DefaultOptions::new()
148 152
        .with_fixint_encoding()
153 +
        .allow_trailing_bytes()
149 154
        .deserialize(bytes)
150 155
}
151 156
@@ -156,5 +161,6 @@
Loading
156 161
{
157 162
    DefaultOptions::new()
158 163
        .with_fixint_encoding()
164 +
        .allow_trailing_bytes()
159 165
        .serialized_size(value)
160 166
}

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Learn more Showing 1 files with coverage changes found.

New file src/config/trailing.rs
New
Loading file...
Files Coverage
src 0.09% 61.43%
Project Totals (11 files) 61.43%
Loading