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
+13 -1

No files matched your search

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