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

Check for overflow in Blob::Reshape #1584

Closed
wants to merge 1 commit into from

Conversation

longjon
Copy link
Contributor

@longjon longjon commented Dec 17, 2014

The check on count_ is more succinct than checking the individual dimensions, and more importantly includes the previously ignored case where bad values for the dimensions cause an overflow for count_, resulting in a silent failure to allocate. Printing the dimension values ensures that no useful debugging information is lost in the change.

@jeffdonahue
Copy link
Contributor

I'd still keep the old checks...even number of negative dimensions?

Previously, bad values for the dimensions could overflow count_,
resulting in a silent failure to allocate.
@longjon
Copy link
Contributor Author

longjon commented Dec 17, 2014

Right, I had a vague sense I was forgetting something... those checks are back now.

@jeffdonahue
Copy link
Contributor

cool, LGTM

@longjon
Copy link
Contributor Author

longjon commented Dec 19, 2014

By the way, overflow can still occur undetected if it happens twice, so that the result is positive. On a related note, we need to change types if we want to be able to allocate blobs larger than 2GB.

It seems like a good idea to change this function so that the allocation either succeeds correctly or fails immediately; currently if you ask for a blob of the wrong (large) size, you get a smaller blob and a headache instead (even with this PR).

@jeffdonahue
Copy link
Contributor

But Jon, users will never need blobs larger than 2 GB!

Would checking for overflow after each multiply fix it? I can do that in #1486 when I'll have to loop over dimensions anyway if so.

@longjon
Copy link
Contributor Author

longjon commented Dec 19, 2014

Not the way it's done here; (1<<31) - 1 is positive; so is ((1<<31) - 1) * 3. However, if one checks the arithmetic with long, it'll work.

@jeffdonahue
Copy link
Contributor

Oh right, makes sense. Checking next_dim <= INT_MAX / current_count seems like it could work too?

@longjon
Copy link
Contributor Author

longjon commented May 7, 2015

Replaced by #2426.

@longjon longjon closed this May 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants