mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-16 23:42:27 +00:00
raw: dng_metadata checks the LinearizationTable count before reading its entries
This commit is contained in:
1 parent
2686ac1f95
commit
9b87ff0a0e
2 files changed
+8
-2
No files matched your search
@@ -135,10 +135,11 @@ impl Metadata<'_, '_> {
|
||||
};
|
||||
let linearization = match self.raw_tag(tags::LINEARIZATION_TABLE) {
|
||||
Some(e) => {
|
||||
let v = self.tiff.uints(e)?;
|
||||
if v.len() > 65_536 {
|
||||
// checked before `uints` allocates a u64 per entry
|
||||
if e.count > 65_536 {
|
||||
return Err(Error::Malformed("LinearizationTable longer than 65536"));
|
||||
}
|
||||
let v = self.tiff.uints(e)?;
|
||||
Some(v.into_iter().map(|x| x.min(65_535) as u16).collect())
|
||||
}
|
||||
None => None,
|
||||
|
||||
@@ -48,6 +48,11 @@ fn processing_tags_are_read_from_the_raw_ifd() {
|
||||
// base_ifd writes CFAPattern 1 0 2 1 (GRBG)
|
||||
assert_eq!(p.cfa, Some(Pattern { rows: 2, cols: 2, colors: vec![1, 0, 2, 1] }));
|
||||
}
|
||||
// a LinearizationTable longer than 65536 entries is refused
|
||||
let long = cfa_raw(|r| {
|
||||
r.set(ct::LINEARIZATION_TABLE, Value::Short(vec![1; 65_537]));
|
||||
});
|
||||
assert!(matches!(with_metadata(&dng(long, ByteOrder::Little), |m| m.params()), Err(Error::Malformed(_))));
|
||||
// absent tags take the DNG defaults
|
||||
let p = with_metadata(&dng(cfa_raw(|_| {}), ByteOrder::Little), |m| m.params().unwrap());
|
||||
assert_eq!((p.active_area, p.linearization, p.black_repeat), (None, None, (1, 1)));
|
||||
|
||||
Reference in new issue
Block a user