diff --git a/CHANGELOG.md b/CHANGELOG.md index e6c2712..eae214e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 0.11.1 - TBD +### Bug fixes +- Changed DBN stream detection to ignore the DBN version + ## 0.11.0 - 2023-09-21 ### Enhancements - Added new `EncodeRecordTextExt` trait which is implemented for the CSV and JSON diff --git a/rust/dbn/src/decode.rs b/rust/dbn/src/decode.rs index 181b280..85e730f 100644 --- a/rust/dbn/src/decode.rs +++ b/rust/dbn/src/decode.rs @@ -458,6 +458,19 @@ mod tests { } } } + + #[test] + fn test_detects_any_dbn_version_as_dbn() { + let mut buf = Vec::new(); + let mut file = File::open(format!("{TEST_DATA_PATH}/test_data.mbo.dbn")).unwrap(); + file.read_to_end(&mut buf).unwrap(); + // change version + buf[3] = crate::DBN_VERSION + 1; + let res = DynDecoder::new_inferred(io::Cursor::new(buf)); + assert!(matches!(res, Err(e) if e + .to_string() + .contains("Can't decode newer version of DBN"))); + } } #[cfg(feature = "async")] diff --git a/rust/dbn/src/decode/dbn.rs b/rust/dbn/src/decode/dbn.rs index 0ef0776..850e11c 100644 --- a/rust/dbn/src/decode/dbn.rs +++ b/rust/dbn/src/decode/dbn.rs @@ -4,9 +4,7 @@ const DBN_PREFIX_LEN: usize = DBN_PREFIX.len(); /// Returns `true` if `bytes` starts with valid uncompressed DBN. pub fn starts_with_prefix(bytes: &[u8]) -> bool { - bytes.len() > DBN_PREFIX_LEN - && &bytes[..DBN_PREFIX_LEN] == DBN_PREFIX - && bytes[DBN_PREFIX_LEN] <= crate::DBN_VERSION + bytes.len() > DBN_PREFIX_LEN && &bytes[..DBN_PREFIX_LEN] == DBN_PREFIX } mod sync;