Skip to content
Merged
Changes from all 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
22 changes: 22 additions & 0 deletions crates/data/src/raster/geotiff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,28 @@ impl Chunks {
})?;
let ((xs, xe), (ys, ye)) = (span.kept(span.cols, x0, cols, k), span.kept(span.rows, y0, rows, k));
let (sc, sr) = (u64::from(span.cols.0), u64::from(span.rows.0));
// Every pixel kept and none to count: a run of a row at a time. Threads reading an image
// take turns placing their chunks, so this part of a read isn't shared among them.
if k == 1 && changed.is_none() {
let (width, left) = (xe.saturating_sub(xs) as usize, (xs - x0) as usize);
for y in ys..ye {
let src = ((y - y0) as usize * stride + left) * per_pixel;
let dst = (y - sr) as usize * ow + (xs - sc) as usize;
let Some(src) = values.get(src..src + width * per_pixel) else { continue };

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardening nit on the new run-of-a-row path. The arithmetic here is unchecked (src + width * per_pixel, and the (y - y0) as usize * stride on line 1205), while the loop below this block keeps the same kind of position math checked and says so in a comment. The values are bounded by values.len() after the shape match, so this can't overflow in practice. Using saturating arithmetic here keeps the two paths consistent and avoids a wrap in release builds if the shape logic changes later:

Suggested change
let Some(src) = values.get(src..src + width * per_pixel) else { continue };
let Some(src) = values.get(src..src.saturating_add(width.saturating_mul(per_pixel))) else { continue };

The continue also drops a whole row without a notice if it is ever reached. The shape check above makes that unreachable, and the old per-pixel loop had the same silent skip, so this is not a regression. Returning an error here would match the "never silent" rule if you want the path to fail loudly instead.

Category: quality

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left for the release quality pass. The shape check above the new path ties these values to the decoded chunk's own length, so the products stay within it and the row is never skipped.

for b in 0..self.samples {
let band = if self.planar { plane } else { b };
let Some(row) = bands.get_mut(band).and_then(|v| v.get_mut(dst..dst + width)) else { continue };
if per_pixel == 1 {
row.copy_from_slice(src);
} else {
for (slot, v) in row.iter_mut().zip(src.iter().skip(b).step_by(per_pixel)) {
*slot = *v;
}
}
}
}
return Ok(());
}
let mut y = ys;
while y < ye {
let mut x = xs;
Expand Down
Loading