fune/third_party/rust/nom/tests/overflow.rs
Emilio Cobos Álvarez 0a80ad4a85 Bug 1621044 - Lockfile changes and revendoring. r=jrmuizel
This updates binjs_meta and thus weedle, bindgen and thus clang-sys
transitively, and the mime / mime_guess crate and thus unicase and
version-check.

Differential Revision: https://phabricator.services.mozilla.com/D66282

--HG--
rename : third_party/rust/lmdb-rkv-sys/tests/fixtures/testdb/lock.mdb => third_party/rust/lmdb-rkv-sys/tests/fixtures/testdb-32/lock.mdb
rename : third_party/rust/mime_guess/Cargo.lock => third_party/rust/nom/Cargo.lock
rename : third_party/rust/nom/src/branch.rs => third_party/rust/nom/src/branch/macros.rs
rename : third_party/rust/nom/src/sequence.rs => third_party/rust/nom/src/sequence/macros.rs
rename : third_party/rust/rkv-0.10.2/.cargo-checksum.json => third_party/rust/rkv-0.10.4/.cargo-checksum.json
rename : third_party/rust/rkv-0.10.2/CODE_OF_CONDUCT.md => third_party/rust/rkv-0.10.4/CODE_OF_CONDUCT.md
rename : third_party/rust/rkv-0.10.2/Cargo.toml => third_party/rust/rkv-0.10.4/Cargo.toml
rename : third_party/rust/rkv-0.10.2/LICENSE => third_party/rust/rkv-0.10.4/LICENSE
rename : third_party/rust/rkv-0.10.2/examples/README.md => third_party/rust/rkv-0.10.4/examples/README.md
rename : third_party/rust/rkv-0.10.2/examples/iterator.rs => third_party/rust/rkv-0.10.4/examples/iterator.rs
rename : third_party/rust/rkv-0.10.2/examples/simple-store.rs => third_party/rust/rkv-0.10.4/examples/simple-store.rs
rename : third_party/rust/rkv-0.10.2/run-all-examples.sh => third_party/rust/rkv-0.10.4/run-all-examples.sh
rename : third_party/rust/rkv-0.10.2/src/bin/dump.rs => third_party/rust/rkv-0.10.4/src/bin/dump.rs
rename : third_party/rust/rkv-0.10.2/src/bin/rand.rs => third_party/rust/rkv-0.10.4/src/bin/rand.rs
rename : third_party/rust/rkv-0.10.2/src/env.rs => third_party/rust/rkv-0.10.4/src/env.rs
rename : third_party/rust/rkv-0.10.2/src/error.rs => third_party/rust/rkv-0.10.4/src/error.rs
rename : third_party/rust/rkv-0.10.2/src/lib.rs => third_party/rust/rkv-0.10.4/src/lib.rs
rename : third_party/rust/rkv-0.10.2/src/manager.rs => third_party/rust/rkv-0.10.4/src/manager.rs
rename : third_party/rust/rkv-0.10.2/src/migrate.rs => third_party/rust/rkv-0.10.4/src/migrate.rs
rename : third_party/rust/rkv-0.10.2/src/readwrite.rs => third_party/rust/rkv-0.10.4/src/readwrite.rs
rename : third_party/rust/rkv-0.10.2/src/store.rs => third_party/rust/rkv-0.10.4/src/store.rs
rename : third_party/rust/rkv-0.10.2/src/store/integer.rs => third_party/rust/rkv-0.10.4/src/store/integer.rs
rename : third_party/rust/rkv-0.10.2/src/store/integermulti.rs => third_party/rust/rkv-0.10.4/src/store/integermulti.rs
rename : third_party/rust/rkv-0.10.2/src/store/multi.rs => third_party/rust/rkv-0.10.4/src/store/multi.rs
rename : third_party/rust/rkv-0.10.2/src/store/single.rs => third_party/rust/rkv-0.10.4/src/store/single.rs
rename : third_party/rust/rkv-0.10.2/src/value.rs => third_party/rust/rkv-0.10.4/src/value.rs
rename : third_party/rust/rkv-0.10.2/tests/integer-store.rs => third_party/rust/rkv-0.10.4/tests/integer-store.rs
rename : third_party/rust/rkv-0.10.2/tests/manager.rs => third_party/rust/rkv-0.10.4/tests/manager.rs
rename : third_party/rust/rkv-0.10.2/tests/multi-integer-store.rs => third_party/rust/rkv-0.10.4/tests/multi-integer-store.rs
rename : third_party/rust/rkv-0.10.2/tests/test_txn.rs => third_party/rust/rkv-0.10.4/tests/test_txn.rs
extra : moz-landing-system : lando
2020-03-10 21:06:36 +00:00

139 lines
3.7 KiB
Rust

#![cfg_attr(feature = "cargo-clippy", allow(unreadable_literal))]
#![cfg(target_pointer_width = "64")]
#[macro_use]
extern crate nom;
use nom::{Err, Needed};
#[cfg(feature = "alloc")]
use nom::number::streaming::be_u64;
// Parser definition
// We request a length that would trigger an overflow if computing consumed + requested
named!(parser01<&[u8],()>,
do_parse!(
hdr: take!(1) >>
data: take!(18446744073709551615) >>
({
let _ = hdr;
let _ = data;
()
})
)
);
// We request a length that would trigger an overflow if computing consumed + requested
named!(parser02<&[u8],(&[u8],&[u8])>,
tuple!(take!(1),take!(18446744073709551615))
);
#[test]
fn overflow_incomplete_do_parse() {
assert_eq!(
parser01(&b"3"[..]),
Err(Err::Incomplete(Needed::Size(18446744073709551615)))
);
}
#[test]
fn overflow_incomplete_tuple() {
assert_eq!(
parser02(&b"3"[..]),
Err(Err::Incomplete(Needed::Size(18446744073709551615)))
);
}
#[test]
#[cfg(feature = "alloc")]
fn overflow_incomplete_length_bytes() {
named!(multi<&[u8], Vec<&[u8]> >, many0!( length_data!(be_u64) ) );
// Trigger an overflow in length_data
assert_eq!(
multi(&b"\x00\x00\x00\x00\x00\x00\x00\x01\xaa\xff\xff\xff\xff\xff\xff\xff\xff\xaa"[..]),
Err(Err::Incomplete(Needed::Size(18446744073709551615)))
);
}
#[test]
#[cfg(feature = "alloc")]
fn overflow_incomplete_many0() {
named!(multi<&[u8], Vec<&[u8]> >, many0!( length_data!(be_u64) ) );
// Trigger an overflow in many0
assert_eq!(
multi(&b"\x00\x00\x00\x00\x00\x00\x00\x01\xaa\xff\xff\xff\xff\xff\xff\xff\xef\xaa"[..]),
Err(Err::Incomplete(Needed::Size(18446744073709551599)))
);
}
#[test]
#[cfg(feature = "alloc")]
fn overflow_incomplete_many1() {
named!(multi<&[u8], Vec<&[u8]> >, many1!( length_data!(be_u64) ) );
// Trigger an overflow in many1
assert_eq!(
multi(&b"\x00\x00\x00\x00\x00\x00\x00\x01\xaa\xff\xff\xff\xff\xff\xff\xff\xef\xaa"[..]),
Err(Err::Incomplete(Needed::Size(18446744073709551599)))
);
}
#[test]
#[cfg(feature = "alloc")]
fn overflow_incomplete_many_till() {
named!(multi<&[u8], (Vec<&[u8]>, &[u8]) >, many_till!( length_data!(be_u64), tag!("abc") ) );
// Trigger an overflow in many_till
assert_eq!(
multi(&b"\x00\x00\x00\x00\x00\x00\x00\x01\xaa\xff\xff\xff\xff\xff\xff\xff\xef\xaa"[..]),
Err(Err::Incomplete(Needed::Size(18446744073709551599)))
);
}
#[test]
#[cfg(feature = "alloc")]
fn overflow_incomplete_many_m_n() {
named!(multi<&[u8], Vec<&[u8]> >, many_m_n!(2, 4, length_data!(be_u64) ) );
// Trigger an overflow in many_m_n
assert_eq!(
multi(&b"\x00\x00\x00\x00\x00\x00\x00\x01\xaa\xff\xff\xff\xff\xff\xff\xff\xef\xaa"[..]),
Err(Err::Incomplete(Needed::Size(18446744073709551599)))
);
}
#[test]
#[cfg(feature = "alloc")]
fn overflow_incomplete_count() {
named!(counter<&[u8], Vec<&[u8]> >, count!( length_data!(be_u64), 2 ) );
assert_eq!(
counter(&b"\x00\x00\x00\x00\x00\x00\x00\x01\xaa\xff\xff\xff\xff\xff\xff\xff\xef\xaa"[..]),
Err(Err::Incomplete(Needed::Size(18446744073709551599)))
);
}
#[test]
#[cfg(feature = "alloc")]
fn overflow_incomplete_length_count() {
use nom::number::streaming::be_u8;
named!(multi<&[u8], Vec<&[u8]> >, length_count!( be_u8, length_data!(be_u64) ) );
assert_eq!(
multi(&b"\x04\x00\x00\x00\x00\x00\x00\x00\x01\xaa\xff\xff\xff\xff\xff\xff\xff\xee\xaa"[..]),
Err(Err::Incomplete(Needed::Size(18446744073709551598)))
);
}
#[test]
#[cfg(feature = "alloc")]
fn overflow_incomplete_length_data() {
named!(multi<&[u8], Vec<&[u8]> >, many0!( length_data!(be_u64) ) );
assert_eq!(
multi(&b"\x00\x00\x00\x00\x00\x00\x00\x01\xaa\xff\xff\xff\xff\xff\xff\xff\xff\xaa"[..]),
Err(Err::Incomplete(Needed::Size(18446744073709551615)))
);
}