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

Replace sox conversion macros with Tensor op #1370

Merged
merged 5 commits into from Mar 8, 2021
Merged

Conversation

mthrok
Copy link
Collaborator

@mthrok mthrok commented Mar 7, 2021

SOX_SIGNED_16BIT_TO_SAMPLE and SOX_SIGNED_32BIT_TO_SAMPLE uses left shift on signed integers, which is UB.
This PR replaces them (and other sox macros for uint8 and float as well) with Tensor operations.

Conversion from signed integer with left shift causes UB (negative left shift)
@mthrok mthrok requested a review from cpuhrsch March 8, 2021 16:21
@mthrok mthrok marked this pull request as ready for review March 8, 2021 16:22
chunk = chunk.to(c10::ScalarType::Double);
chunk *= 2147483648.;
chunk.clamp_(INT32_MIN, INT32_MAX);
chunk = chunk.to(c10::ScalarType::Int);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that this will guarantee that chunk is contiguous afterwards. I'd call into "contiguous" anyway to be sure. Same applies for the other cases.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool. will update

@mthrok mthrok merged commit 0ea475a into pytorch:master Mar 8, 2021
@mthrok mthrok deleted the fix-ub branch March 8, 2021 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants