That sounds correct. The key point is that the loops are over the output space: you step through each position in the output space, not skipping any. Then at each point, you have to calculate where that maps to in the input space. For that you multiply by the stride, as you described.
The other possibility is that you did not calculate the shape of the output object correctly. Here’s a thread which shows some examples of all the calculated dimensions.
The other clue is that the error occurs on the width dimension. The height and width are handled the same way, right?
The other thing to investigate is when this error gets thrown: is it on the very first iteration or do you actually run off the end?