asmarques / adsb Goto Github PK
View Code? Open in Web Editor NEWA Rust parser for ADS-B/Mode-S messages.
License: Apache License 2.0
A Rust parser for ADS-B/Mode-S messages.
License: Apache License 2.0
Found using cargo-fuzz
.
Input:
\x8a\x8f\xff`J\xb4\xc0
Test program:
extern crate adsb;
fn main() {
let data : &[u8] = b"\x8a\x8f\xff`J\xb4\xc0";
let _ = adsb::parse_binary(data);
}
thread 'main' panicked at 'attempt to multiply with overflow', src/parser.rs:44:10
stack backtrace:
0: backtrace::backtrace::libunwind::trace
at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.29/src/backtrace/libunwind.rs:88
1: backtrace::backtrace::trace_unsynchronized
at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.29/src/backtrace/mod.rs:66
2: std::sys_common::backtrace::_print
at src/libstd/sys_common/backtrace.rs:47
3: std::sys_common::backtrace::print
at src/libstd/sys_common/backtrace.rs:36
4: std::panicking::default_hook::{{closure}}
at src/libstd/panicking.rs:200
5: std::panicking::default_hook
at src/libstd/panicking.rs:214
6: std::panicking::rust_panic_with_hook
at src/libstd/panicking.rs:477
7: std::panicking::continue_panic_fmt
at src/libstd/panicking.rs:384
8: rust_begin_unwind
at src/libstd/panicking.rs:311
9: core::panicking::panic_fmt
at src/libcore/panicking.rs:85
10: core::panicking::panic
at src/libcore/panicking.rs:49
11: adsb::parser::parse_altitude
at src/parser.rs:44
12: adsb::parser::parse_airborne_position
at ./<::nom::macros::named macros>:13
13: adsb::parser::parse_adsb_message_kind
at ./<::nom::macros::named macros>:13
14: adsb::parser::parse_adsb_message
at ./<::nom::macros::named macros>:13
15: adsb::parser::parse_message_kind
at ./<::nom::macros::named macros>:13
16: adsb::parser::parse_message
at ./<::nom::macros::named macros>:13
17: adsb::parser::parse_binary
at src/parser.rs:181
18: a::main
at examples/a.rs:5
19: std::rt::lang_start::{{closure}}
at /rustc/17e62f77f954bed97aae839624bfd6dd68342daf/src/libstd/rt.rs:64
20: std::rt::lang_start_internal::{{closure}}
at src/libstd/rt.rs:49
21: std::panicking::try::do_call
at src/libstd/panicking.rs:296
22: __rust_maybe_catch_panic
at src/libpanic_unwind/lib.rs:82
23: std::panicking::try
at src/libstd/panicking.rs:275
24: std::panic::catch_unwind
at src/libstd/panic.rs:388
25: std::rt::lang_start_internal
at src/libstd/rt.rs:48
26: std::rt::lang_start
at /rustc/17e62f77f954bed97aae839624bfd6dd68342daf/src/libstd/rt.rs:64
27: main
28: __libc_start_main
29: _start
Page 47 of http://www.anteni.net/adsb/Doc/1090-WP-14-09R1.pdf says
For latitudes at or near the N or S pole, where the above formula would either be undefined or yield NL(lat) = 0, the value returned by the NL( ) function shall be 1.
but cpr_nl
as currently defined can return 0.
#[test]
fn cpr_nl1() {
assert_eq!(cpr_nl(89.9), 1);
assert_eq!(cpr_nl(-89.9), 1);
}
running 1 test
thread 'cpr::tests::cpr_nl1' panicked at 'assertion failed: `(left == right)`
left: `0`,
right: `1`', src/cpr.rs:105:9
This can lead to a panic when decoding positions:
#[test]
fn cpr_calculate_position2() {
let even = CPRFrame {
position: Position {
latitude: 108011.0,
longitude: 110088.0,
},
parity: Parity::Even,
};
let odd = CPRFrame {
position: Position {
latitude: 75050.0,
longitude: 36777.0,
},
parity: Parity::Odd,
};
let position = get_position((&even, &odd)).unwrap();
assert_approx_eq!(position.latitude, 88.91747426178496);
assert_approx_eq!(position.longitude, 101.01104736328125);
}
running 1 test
thread 'cpr::tests::cpr_calculate_position2' panicked at 'attempt to subtract with overflow', src/cpr.rs:88:23
stack backtrace:
0: rust_begin_unwind
at /rustc/d98d2f57d9b98325ff075c343d2c7695b66dfa7d/library/std/src/panicking.rs:493:5
1: core::panicking::panic_fmt
at /rustc/d98d2f57d9b98325ff075c343d2c7695b66dfa7d/library/core/src/panicking.rs:92:14
2: core::panicking::panic
at /rustc/d98d2f57d9b98325ff075c343d2c7695b66dfa7d/library/core/src/panicking.rs:50:5
3: adsb::cpr::get_lat_lon
at ./src/cpr.rs:88:23
4: adsb::cpr::get_position
at ./src/cpr.rs:74:22
5: adsb::cpr::tests::cpr_calculate_position2
at ./src/cpr.rs:126:24
I found this by running the decoder over about 14 billion pings I've recorded from the Los Angeles area. In that many pings you get some weird data, and this one cropped up about 4 million pings into the test, where I accidentally used even and odd frames that were broadcast about 10 hours and many miles apart (and may be corrupted/weird anyway).
Due to how the variants of MessageKind and ADSBMessageKind are built, they are pretty easy to create, but from a user of the API's perspective, due to the individual variants being Enums, they cannot be typed and assigned to new variables.
I'd suggest to convert messageKinds into individual types, but they consumes a common trait that can still be extended using impl on both of these types for creation purposes. This is particularly impactful on the enum variants that have highly differing contents and sub-fields. By implementing this, in theory you could then the following which is not really possible as Enums aren't types:
let packet = parse_avr(&input).unwrap();
let adsb: ADSBMessage = packet.kind;
let postition: Position = adsb.kind.cpr_frame.position;
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.