Modified the validation for ascii tag type

This commit is contained in:
Emmanuel Antony committed 2021-03-20 08:47:47 +05:30
1 parent 53d0256585
commit f5754159cb
2 files changed
+15 -3

No files matched your search

+8 -3
View File
@@ -4,6 +4,7 @@ use std::collections::HashMap;
use std::convert::{TryFrom, TryInto};
use std::io::{self, Read, Seek};
use std::mem;
use std::str;
use super::stream::{ByteOrder, EndianReader, SmartReader};
use crate::tags::{Tag, Type};
@@ -420,9 +421,13 @@ impl Entry {
Type::ASCII => {
let mut buf = vec![0; self.count as usize];
self.r(bo).read_exact(&mut buf)?;
let v = String::from_utf8(buf)?;
let v = v.trim_matches(char::from(0));
return Ok(Ascii(v.into()));
if buf.is_ascii() && buf.ends_with(&[0]) {
let v = str::from_utf8(&buf)?;
let v = v.trim_matches(char::from(0));
return Ok(Ascii(v.into()));
} else {
return Err(TiffError::FormatError(TiffFormatError::InvalidTag));
}
}
Type::UNDEFINED => {
return Ok(List(