Merge pull request #121 from emmanuelantony2000/ascii_tag_validation

Validation for ASCII tag type
This commit is contained in:
HeroicKatora authored and GitHub committed 2021-03-20 13:28:32 +01:00
commit 6fe9b78509
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::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)?;
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(
+7
View File
@@ -1,6 +1,7 @@
use std::error::Error;
use std::fmt;
use std::io;
use std::str;
use std::string;
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 {
fn from(_err: string::FromUtf8Error) -> TiffError {
TiffError::FormatError(TiffFormatError::InvalidTag)