Skip to content
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

Resolve integer overflow when running on a large 3D image #249

Merged
merged 1 commit into from Sep 12, 2023

Conversation

ximion
Copy link
Contributor

@ximion ximion commented Sep 2, 2023

Hi!
In a computation like x+ynx+z(nxny) if the sub-computation ynx or z*(nx*ny) overflows the size of a 32-bit integer, we will get a bogus result even though the final destination is a 64-bit integer (since all the operands are 32-bit ints). The solution is to promote at least one operand to a bigger-sized integer. Since long can also be 32-bit on 32-bit architectures, we just use explicit named types here.
This patch also fixes a few cases of comparisons of integers with different signs.

Resolves: #235

In a computation like x+y*nx+z*(nx*ny) if the sub-computation y*nx or
z*(nx*ny) overflows the size of a 32-bit integer, we will get a bogus
result even though the final destination is a 64-bit integer.
The solution is to promote at least one operand to a bigger-sized
integer. Since long can also be 32-bit on 32-bit architectures, we just
use explicit named types here.
This patch also fixes a few cases of comparisons of integers with
different signs.

Resolves: stardist#235
@maweigert
Copy link
Member

Indeed all indices/offsets should have been uint64 anyway, so this is a good fix. Thanks!

@ximion ximion mentioned this pull request Sep 2, 2023
@maweigert maweigert merged commit 9d6fac7 into stardist:master Sep 12, 2023
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crashes when running predict_instances on a 3D image
3 participants