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

serializedSize(): Always return a double (to lower the risk for integer overflow downstream) #123

Closed
HenrikBengtsson opened this issue Dec 15, 2024 · 4 comments
Assignees
Milestone

Comments

@HenrikBengtsson
Copy link
Collaborator

Background

The serializedSize() function returns the number of bytes it would take to serialize an object. It returns an integer, unless it is greater than .Machine$integer.max (= ~2.15 GB), in case it returns a double (

if (count > R_INT_MAX) {
return(ScalarReal((double) count));
} else {
return(ScalarInteger(count));
}
).

Issue

This agility of serializedSize() to return an integer, if sufficient, can lead to silent errors downstream. For instance, two objects might be small enough to return an integer;

size1 <- serializedSize(x1)
size2 <- serializedSize(x2)

but large enough for their sum to overflow;

> size1 + size2
NA
Warning message:
In size1 + size2:
  NAs produced by integer overflow

This problem was first reported by @ycl6 in futureverse/future#755.

Suggestion

Change serializedSize() to always return a double. FWIW, that is what utils::object.size() does.

/cc @coolbutuseless

@HenrikBengtsson
Copy link
Collaborator Author

Implemented in parallelly (>= 1.40.1-9007).

@HenrikBengtsson
Copy link
Collaborator Author

@ycl6, parallelly 1.41.0 fixing this is now on CRAN.

@ycl6
Copy link

ycl6 commented Dec 18, 2024

Thanks @HenrikBengtsson for updating the CRAN package so swiftly!
I've been using parallelly 1.40.1-9007 and works perfectly 👍

@HenrikBengtsson
Copy link
Collaborator Author

@ycl6 , thanks again for reporting and working with downstream packages and issue trackers.

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

No branches or pull requests

2 participants