Skip to content

Commit 6fd47e0

Browse files
committed
Fix negative padding breaking calc_padding_regions()
This was caught by the fuzzing tests.
1 parent 1365788 commit 6fd47e0

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/impl/padding_edges.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ function calc_padding_regions(dims)
2626
# spillage is slightly more complicated; we first figure out how many elements of
2727
# high padding are wasted (e.g. through strides not fitting to the end perfectly)
2828
# subtract that from the high padding, then do the same:
29-
calc_lo_spill(O, S, P) = min(ceil(Int, P/S), O)
29+
calc_lo_spill(O, S, P) = max(min(ceil(Int, P/S), O),0)
3030
@inline function calc_hi_spill(O, S, Pl, Ph, K, D, I)
3131
wasted_Ph = (I + Pl + Ph - (K - 1)*D - 1)%S
32-
return min(ceil(Int, (Ph - wasted_Ph)/S), O)
32+
return max(min(ceil(Int, (Ph - wasted_Ph)/S), O), 0)
3333
end
3434

3535
spill_w_lo = calc_lo_spill(out_width, stride_w, pad_w_lo)

0 commit comments

Comments
 (0)