mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 05:14:24 +00:00
202 upstream commits since 6cb00467a. Resolutions:
- craft-window, craft-platform: ours. Upstream's frame policy v2, restore
store and GNOME light/wait_first are the versions carried on 28 Oct;
ours moved place() to craft-behavior and kept LayoutWatch and the
appearance/portal.rs split.
- craft-timeline: ours. craft-time (crates/time) lands as upstream wrote
it and is not yet used by craft-timeline.
- Old crates/ui modules stay removed. Upstream's frosted backdrops, shape
gallery, dialog tabs and the iconic flyout top-edge rendering are not
carried. The #1094 model half is in craft-behavior's dock:
Group::flyout_offset and Action::MoveFlyoutTop.
- craft-update: #586 Save and Update, the install probe on the check
thread and quiet per-user MSI self-updates, carried into updater.rs,
stack_dialogs.rs, install/windows.rs and self_update/helper.rs.
- craft-jpeg: progressive Huffman decoding, carried into huffman.rs,
parse.rs and scan.rs.
- craft-print: the driver settings dialog's new tests and the bounded
XML parse's tests, as trials.
- Test-only conflicts: upstream tests from before the base that our side
cut stay cut; tests new upstream are kept.
54 lines
1.8 KiB
Rust
54 lines
1.8 KiB
Rust
//! Binary DXF writing (#421): values are written in their group code's kind, and hostile binary
|
|
//! input never panics.
|
|
|
|
use craft_dxf::{Tag, Value, parse, write_binary};
|
|
|
|
fn sample() -> Vec<Tag> {
|
|
vec![
|
|
Tag::s(0, "SECTION"),
|
|
Tag::s(2, "ENTITIES"),
|
|
Tag::s(0, "TEXT"),
|
|
Tag::s(5, "1F"),
|
|
Tag::f(10, -3.25),
|
|
Tag::i(62, 5),
|
|
Tag::i(90, 70_000),
|
|
Tag::i(160, 1 << 40),
|
|
Tag::new(290, Value::Bool(true)),
|
|
Tag::new(310, Value::Hex("00FFA5".into())),
|
|
Tag::s(1, "图号 Café 😀"),
|
|
Tag::i(1071, -2),
|
|
Tag::s(0, "ENDSEC"),
|
|
Tag::s(0, "EOF"),
|
|
]
|
|
}
|
|
|
|
#[test]
|
|
fn binary_converts_values_to_their_codes_kind() {
|
|
// A number held as text at a numeric code, an out-of-range 16-bit value, a long chunk.
|
|
let long = "AB".repeat(300);
|
|
let tags = vec![Tag::s(70, "12"), Tag::i(62, 1 << 20), Tag::new(310, Value::Hex(long)), Tag::s(0, "EOF")];
|
|
let back = parse(&write_binary(&tags, true)).unwrap();
|
|
assert_eq!(back[0], Tag::i(70, 12));
|
|
assert_eq!(back[1], Tag::i(62, i64::from(i16::MAX)));
|
|
let sizes: Vec<usize> = back.iter().filter(|t| t.code == 310).map(|t| t.str().len()).collect();
|
|
assert_eq!(sizes, vec![254, 254, 92], "300 bytes are split into chunks of at most 127 (254 hex digits)");
|
|
}
|
|
|
|
#[test]
|
|
fn hostile_binary_input_never_panics() {
|
|
let good = write_binary(&sample(), true);
|
|
// Every truncation, and every single-byte corruption of the body.
|
|
for n in 0..good.len() {
|
|
let _ = parse(good.get(..n).unwrap());
|
|
}
|
|
for i in 22..good.len() {
|
|
for b in [0u8, 0x7f, 0xff] {
|
|
let mut bad = good.clone();
|
|
bad[i] = b;
|
|
let _ = parse(&bad);
|
|
}
|
|
}
|
|
// A sentinel and nothing else is not a drawing.
|
|
assert!(parse(b"AutoCAD Binary DXF\r\n\x1a\0").is_err());
|
|
}
|