Skip to content

Commit

Permalink
FIX: Change DBN detection to ignore version
Browse files Browse the repository at this point in the history
  • Loading branch information
threecgreen committed Oct 5, 2023
1 parent 0546f0f commit 157a2c8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
13 changes: 13 additions & 0 deletions rust/dbn/src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
4 changes: 1 addition & 3 deletions rust/dbn/src/decode/dbn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 157a2c8

Please sign in to comment.