halide / Halide

a language for fast, portable data-parallel computation
https://halide-lang.org
Other
5.92k stars 1.07k forks source link

HalideBuffer::crop() lets you crop to illegal bounds #2951

Open steven-johnson opened 6 years ago

steven-johnson commented 6 years ago

If you give it a min,extent pair that is outside the current bounds of the Buffer, it will produce a buffer with illegal extents that will allow out of bounds writes. We should reality-check the input args and assert and/or clamp appropriately.

abadams commented 6 years ago

Asserting would remove the ability to un-crop in cases where you know the buffer you have is a small window on a larger thing. E.g. you might want to make an ROI and then march it along inside the larger thing by repeatedly cropping a little over to the right.

IMO this is an ugly thing to do and we should be OK with forbidding it, but I just wanted to note that there is a memory-safe use-case that we'd be intentionally ruling out.

steven-johnson commented 6 years ago

where you know the buffer you have is a small window on a larger thing

This sounds like a Bad Idea; if you know you need to do this, you should really restructure to pass the larger thing in.

abadams commented 6 years ago

Agreed, just wanted to leave a record that this is intentional.