fix(dxf): split binary hex payloads into chunks of at most 127 bytes (#1147) (#1148)

This commit is contained in:
Nicolas Bohn authored and GitHub committed 2026-11-12 21:49:37 -05:00
1 parent f92a91afa4
commit 5056c13ef7
4 files changed
+6 -10

No files matched your search

+3 -3
View File
@@ -768,7 +768,7 @@ fn ascii(tags: &[Tag], strings: Strings) -> Vec<u8> {
/// Write tags as binary DXF (DXF Reference, "Binary DXF Files", R13+ layout): the sentinel,
/// then per tag a 2-byte little-endian group code and the value in the binary form of the code's
/// [`Kind`]: a zero-terminated string, an 8-byte real, a 2-, 4- or 8-byte integer, a 1-byte
/// boolean, or a binary chunk (one length byte, then up to 255 bytes; longer data is split into
/// boolean, or a binary chunk (one length byte, then up to 127 bytes; longer data is split into
/// several groups of the same code). Strings are UTF-8 when `utf8` (R2007+), otherwise escaped as
/// in [`write_ascii`]. A tag's value is converted to its code's kind, so a number written as text
/// is stored as a number; a code outside the 16-bit range is skipped.
@@ -822,8 +822,8 @@ fn binary(tags: &[Tag], strings: Strings) -> Vec<u8> {
}
Kind::Hex => {
let bytes = hex_bytes(&t.value.as_str());
// An empty chunk is still one group, as in ASCII.
let mut chunks: Vec<&[u8]> = bytes.chunks(255).collect();
// At most 127 bytes per group, as in ASCII; an empty chunk is still one group.
let mut chunks: Vec<&[u8]> = bytes.chunks(127).collect();
if chunks.is_empty() {
chunks.push(&[]);
}
+2 -3
View File
@@ -44,9 +44,8 @@ fn binary_converts_values_to_their_codes_kind() {
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)));
assert_eq!(back[2].code, 310);
assert_eq!(back[3].code, 310, "300 bytes are split into chunks of at most 255");
assert_eq!(back[2].str().len() + back[3].str().len(), 600);
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]
-3
View File
@@ -2,7 +2,6 @@
//! 1004 specify at most 127 payload bytes per chunk, even though a length byte represents 255.
//! Inspect writer bytes without our parser; accept any compliant partition preserving payload,
//! code and following-record framing. Oversized binary read fixtures test tolerance only.
//! Pending writer regressions extend the chunk-size finding in issue #1025.
//! Public DXF Reference, Group Codes in Numerical Order and Binary DXF Files:
//! <https://help.autodesk.com/cloudhelp/2025/ENU/AutoCAD-DXF/files/GUID-3F0380A5-1C15-464D-BC66-2C5F094BCFB9.htm>
//! <https://help.autodesk.com/cloudhelp/2025/ENU/AutoCAD-DXF/files/GUID-FC1C3C69-DBC2-49E4-893A-000D6538C0FE.htm>
@@ -100,7 +99,6 @@ fn binary_reader_tolerates_the_full_length_byte_domain() {
}
#[test]
#[ignore = "Confirmed ASCII DXF writer nonconformance: hex payloads above 127 bytes are emitted as one oversized chunk"]
fn ascii_writer_splits_large_payloads_into_conforming_chunks() {
for code in (310..=319).chain([1004]) {
for length in [128, 254, 255, 256, 1024] {
@@ -112,7 +110,6 @@ fn ascii_writer_splits_large_payloads_into_conforming_chunks() {
}
#[test]
#[ignore = "Confirmed binary DXF writer nonconformance: 255-byte partitioning exceeds the documented 127-byte group limit"]
fn binary_writer_splits_large_payloads_into_conforming_chunks() {
for code in (310..=319).chain([1004]) {
for length in [128, 254, 255, 256, 1024] {
+1 -1
View File
@@ -120,7 +120,7 @@ fn hex_chunks_keep_bytes_and_order() {
// DXF groups 310–319 and 1004 permit 127 payload bytes per chunk. A binary length
// byte can represent more, but that is reader tolerance, not writer conformance.
// Larger payloads need chunk-size/reassembly checks rather than exact tag equality;
// see hex_chunks.rs for the independent wire checks and pending writer regressions.
// see hex_chunks.rs for the independent wire checks.
for length in [0, 1, 2, 126, 127] {
let hex: String = (0..length).fold(String::new(), |mut out, i| {
use std::fmt::Write as _;