Skip to content

Conversation

pipitochka
Copy link

#949
Added validation to prevent operations on invalid tensors with null data pointers but non-zero sizes

Copy link

meta-cla bot commented Oct 9, 2025

Hi @pipitochka!

Thank you for your pull request and welcome to our community.

Action Required

In 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.

Process

In 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 CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

Copy link

meta-cla bot commented Oct 9, 2025

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 9, 2025
samples.numel() == 0 || samples.data_ptr() != nullptr,
"Samples tensor has null data pointer but non-zero numel. ",
"This indicates an invalid tensor state.");

Copy link
Contributor

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.

Copy link
Author

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)

Copy link
Author

@pipitochka pipitochka Oct 9, 2025

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;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Meta Open Source bot.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants