-
Notifications
You must be signed in to change notification settings - Fork 64
fix invalid tensors #950
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
base: main
Are you sure you want to change the base?
fix invalid tensors #950
Conversation
Hi @pipitochka! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
samples.numel() == 0 || samples.data_ptr() != nullptr, | ||
"Samples tensor has null data pointer but non-zero numel. ", | ||
"This indicates an invalid tensor state."); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @pipitochka . Can you please share more details about how the fuzzer managed to create a tensor with numel() > 0
and data_ptr() == nullptr
?
I wonder how it's even possible to end up with such tensors through normal torch operations.
Note for myself: right now if we pass an a tensor with numel == 0 we get a decent error message:
E RuntimeError: Desired number of channels (0) is not supported by the encoder. Supported number of channels are: 1, 2.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I done it by torch::load(input_data, dir)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My function to fuzzing
char name[] = "/tmp/torch-fuzz-XXXXXX";
char *dir = mktemp(name);
std::ofstream fp;
fp.open(dir, std::ios::out | std::ios::binary);
fp.write((char *)data, size);
fp.close();
if (size <= 0) {
unlink(dir);
return 0;
}
try {
torch::Tensor input_data;
torch::load(input_data, dir);
int mode = (int)data[0] % 5;
facebook::torchcodec::AudioStreamOptions aso;
aso.bitRate = mode;
aso.numChannels = 1;
aso.sampleRate = 1;
std::string fileName = "tmp";
facebook::torchcodec::AudioEncoder encoder = facebook::torchcodec::AudioEncoder(
input_data, mode, fileName, aso);
auto result = encoder.encodeToTensor();
} catch (const c10::Error &e) {
} catch (const torch::jit::ErrorReport &e) {
} catch (const std::runtime_error &e) {
}
unlink(dir);
return 0;
#949
Added validation to prevent operations on invalid tensors with null data pointers but non-zero sizes