Skip to content

Exponential overflow header buffer #83

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/cog.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::sync::Arc;

use crate::error::AsyncTiffResult;
use crate::ifd::ImageFileDirectories;
use crate::reader::{AsyncCursor, AsyncFileReader};
Expand All @@ -15,7 +13,7 @@ impl TIFF {
/// Open a new TIFF file.
///
/// This will read all the Image File Directories (IFDs) in the file.
pub async fn try_open(reader: Arc<dyn AsyncFileReader>) -> AsyncTiffResult<Self> {
pub async fn try_open(reader: &mut dyn AsyncFileReader) -> AsyncTiffResult<Self> {
let mut cursor = AsyncCursor::try_open_tiff(reader).await?;
let version = cursor.read_u16().await?;

Expand Down Expand Up @@ -74,13 +72,13 @@ mod test {
let folder = "/Users/kyle/github/developmentseed/async-tiff/";
let path = object_store::path::Path::parse("m_4007307_sw_18_060_20220803.tif").unwrap();
let store = Arc::new(LocalFileSystem::new_with_prefix(folder).unwrap());
let reader = Arc::new(ObjectReader::new(store, path));
let mut reader = Box::new(ObjectReader::new(store, path));

let cog_reader = TIFF::try_open(reader.clone()).await.unwrap();
let cog_reader = TIFF::try_open(reader.as_mut()).await.unwrap();

let ifd = &cog_reader.ifds.as_ref()[1];
let decoder_registry = DecoderRegistry::default();
let tile = ifd.fetch_tile(0, 0, reader.as_ref()).await.unwrap();
let tile = ifd.fetch_tile(0, 0, reader.as_mut()).await.unwrap();
let tile = tile.decode(&decoder_registry).unwrap();
std::fs::write("img.buf", tile).unwrap();
}
Expand Down
12 changes: 6 additions & 6 deletions src/ifd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl AsRef<[ImageFileDirectory]> for ImageFileDirectories {

impl ImageFileDirectories {
pub(crate) async fn open(
cursor: &mut AsyncCursor,
cursor: &mut AsyncCursor<'_>,
ifd_offset: u64,
bigtiff: bool,
) -> AsyncTiffResult<Self> {
Expand Down Expand Up @@ -184,7 +184,7 @@ pub struct ImageFileDirectory {
impl ImageFileDirectory {
/// Read and parse the IFD starting at the given file offset
async fn read(
cursor: &mut AsyncCursor,
cursor: &mut AsyncCursor<'_>,
ifd_start: u64,
bigtiff: bool,
) -> AsyncTiffResult<Self> {
Expand Down Expand Up @@ -774,7 +774,7 @@ impl ImageFileDirectory {
&self,
x: usize,
y: usize,
reader: &dyn AsyncFileReader,
reader: &mut dyn AsyncFileReader,
) -> AsyncTiffResult<Tile> {
let range = self
.get_tile_byte_range(x, y)
Expand All @@ -795,7 +795,7 @@ impl ImageFileDirectory {
&self,
x: &[usize],
y: &[usize],
reader: &dyn AsyncFileReader,
reader: &mut dyn AsyncFileReader,
) -> AsyncTiffResult<Vec<Tile>> {
assert_eq!(x.len(), y.len(), "x and y should have same len");

Expand Down Expand Up @@ -838,7 +838,7 @@ impl ImageFileDirectory {
}

/// Read a single tag from the cursor
async fn read_tag(cursor: &mut AsyncCursor, bigtiff: bool) -> AsyncTiffResult<(Tag, Value)> {
async fn read_tag(cursor: &mut AsyncCursor<'_>, bigtiff: bool) -> AsyncTiffResult<(Tag, Value)> {
let start_cursor_position = cursor.position();

let tag_name = Tag::from_u16_exhaustive(cursor.read_u16().await?);
Expand Down Expand Up @@ -868,7 +868,7 @@ async fn read_tag(cursor: &mut AsyncCursor, bigtiff: bool) -> AsyncTiffResult<(T
// This is derived from the upstream tiff crate:
// https://github.com/image-rs/image-tiff/blob/6dc7a266d30291db1e706c8133357931f9e2a053/src/decoder/ifd.rs#L369-L639
async fn read_tag_value(
cursor: &mut AsyncCursor,
cursor: &mut AsyncCursor<'_>,
tag_type: Type,
count: u64,
bigtiff: bool,
Expand Down
Loading
Loading