Merge pull request #121 from emmanuelantony2000/ascii_tag_validation
Validation for ASCII tag type
This commit is contained in:
2 files changed
+15
-3
No files matched your search
+8
-3
@@ -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 = v.trim_matches(char::from(0));
|
let v = str::from_utf8(&buf)?;
|
||||||
return Ok(Ascii(v.into()));
|
let v = v.trim_matches(char::from(0));
|
||||||
|
return Ok(Ascii(v.into()));
|
||||||
|
} else {
|
||||||
|
return Err(TiffError::FormatError(TiffFormatError::InvalidTag));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Type::UNDEFINED => {
|
Type::UNDEFINED => {
|
||||||
return Ok(List(
|
return Ok(List(
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
Reference in new issue
Block a user