Skip to content

Catch invalid scalar type when parsing tensors #1518

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

Closed
wants to merge 3 commits into from

Conversation

dbort
Copy link
Contributor

@dbort dbort commented Jan 3, 2024

Summary:
Fail non-fatally when encountering an unknown/unhandled ScalarType in a .pte file. As part of this:

  • Move the "types not supported yet" logic out of scalar_type_util and into tensor_parser, since that decision is an aspect of the runtime and not a fundamental aspect of ScalarType.
  • Remove the now-duplicate sizeof_scalar_type function, which is the same as the exsting elementSize function. Before this diff, sizeof_scalar_type did the "unsupported" checks that have now moved.
  • Add an isValid() function to let users of ScalarType know whether a given enum value is legit. This makes it possible to avoid the fatal error when calling elementSize on a bad value.
  • Add unit tests for the new isValid().

Differential Revision: D52451738

dbort added 3 commits January 2, 2024 16:15
Summary: Don't fail fatally if the .pte file contains an unknown type enum value. Discovered by lionhead fuzzing.

Differential Revision: D52493415
Summary: Flatbuffer array fields can be missing, so we need to check for `nullptr` before calling `size()` on them. Discovered by lionhead fuzzing.

Differential Revision: D52493423
Summary:
Fail non-fatally when encountering an unknown/unhandled `ScalarType` in a `.pte` file. As part of this:
- Move the "types not supported yet" logic out of `scalar_type_util` and into `tensor_parser`, since that decision is an aspect of the runtime and not a fundamental aspect of `ScalarType`.
- Remove the now-duplicate `sizeof_scalar_type` function, which is the same as the exsting `elementSize` function. Before this diff, `sizeof_scalar_type` did the "unsupported" checks that have now moved.
- Add an `isValid()` function to let users of `ScalarType` know whether a given enum value is legit. This makes it possible to avoid the fatal error when calling `elementSize` on a bad value.
- Add unit tests for the new `isValid()`.

Differential Revision: D52451738
Copy link

pytorch-bot bot commented Jan 3, 2024

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/1518

Note: Links to docs will display an error until the docs builds have been completed.

✅ You can merge normally! (1 Unrelated Failure)

As of commit 94735dd with merge base a81c2d4 (image):

FLAKY - The following job failed but was likely due to flakiness present on trunk:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jan 3, 2024
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D52451738

dbort added a commit to dbort/executorch that referenced this pull request Jan 3, 2024
Summary:

Fail non-fatally when encountering an unknown/unhandled `ScalarType` in a `.pte` file. As part of this:
- Move the "types not supported yet" logic out of `scalar_type_util` and into `tensor_parser`, since that decision is an aspect of the runtime and not a fundamental aspect of `ScalarType`.
- Remove the now-duplicate `sizeof_scalar_type` function, which is the same as the exsting `elementSize` function. Before this diff, `sizeof_scalar_type` did the "unsupported" checks that have now moved.
- Add an `isValid()` function to let users of `ScalarType` know whether a given enum value is legit. This makes it possible to avoid the fatal error when calling `elementSize` on a bad value.
- Add unit tests for the new `isValid()`.

Differential Revision: D52451738
dbort added a commit to dbort/executorch that referenced this pull request Jan 3, 2024
Summary:

Fail non-fatally when encountering an unknown/unhandled `ScalarType` in a `.pte` file. As part of this:
- Move the "types not supported yet" logic out of `scalar_type_util` and into `tensor_parser`, since that decision is an aspect of the runtime and not a fundamental aspect of `ScalarType`.
- Remove the now-duplicate `sizeof_scalar_type` function, which is the same as the exsting `elementSize` function. Before this diff, `sizeof_scalar_type` did the "unsupported" checks that have now moved.
- Add an `isValid()` function to let users of `ScalarType` know whether a given enum value is legit. This makes it possible to avoid the fatal error when calling `elementSize` on a bad value.
- Add unit tests for the new `isValid()`.

Differential Revision: D52451738
dbort added a commit to dbort/executorch that referenced this pull request Jan 3, 2024
Summary:

Fail non-fatally when encountering an unknown/unhandled `ScalarType` in a `.pte` file. As part of this:
- Move the "types not supported yet" logic out of `scalar_type_util` and into `tensor_parser`, since that decision is an aspect of the runtime and not a fundamental aspect of `ScalarType`.
- Remove the now-duplicate `sizeof_scalar_type` function, which is the same as the exsting `elementSize` function. Before this diff, `sizeof_scalar_type` did the "unsupported" checks that have now moved.
- Add an `isValid()` function to let users of `ScalarType` know whether a given enum value is legit. This makes it possible to avoid the fatal error when calling `elementSize` on a bad value.
- Add unit tests for the new `isValid()`.

Differential Revision: D52451738
dbort added a commit to dbort/executorch that referenced this pull request Jan 3, 2024
Summary:

Fail non-fatally when encountering an unknown/unhandled `ScalarType` in a `.pte` file. As part of this:
- Move the "types not supported yet" logic out of `scalar_type_util` and into `tensor_parser`, since that decision is an aspect of the runtime and not a fundamental aspect of `ScalarType`.
- Remove the now-duplicate `sizeof_scalar_type` function, which is the same as the exsting `elementSize` function. Before this diff, `sizeof_scalar_type` did the "unsupported" checks that have now moved.
- Add an `isValid()` function to let users of `ScalarType` know whether a given enum value is legit. This makes it possible to avoid the fatal error when calling `elementSize` on a bad value.
- Add unit tests for the new `isValid()`.

Differential Revision: D52451738
dbort added a commit to dbort/executorch that referenced this pull request Jan 3, 2024
Summary:

Fail non-fatally when encountering an unknown/unhandled `ScalarType` in a `.pte` file. As part of this:
- Move the "types not supported yet" logic out of `scalar_type_util` and into `tensor_parser`, since that decision is an aspect of the runtime and not a fundamental aspect of `ScalarType`.
- Remove the now-duplicate `sizeof_scalar_type` function, which is the same as the exsting `elementSize` function. Before this diff, `sizeof_scalar_type` did the "unsupported" checks that have now moved.
- Add an `isValid()` function to let users of `ScalarType` know whether a given enum value is legit. This makes it possible to avoid the fatal error when calling `elementSize` on a bad value.
- Add unit tests for the new `isValid()`.

Differential Revision: D52451738
dbort added a commit to dbort/executorch that referenced this pull request Jan 3, 2024
Summary:

Fail non-fatally when encountering an unknown/unhandled `ScalarType` in a `.pte` file. As part of this:
- Move the "types not supported yet" logic out of `scalar_type_util` and into `tensor_parser`, since that decision is an aspect of the runtime and not a fundamental aspect of `ScalarType`.
- Remove the now-duplicate `sizeof_scalar_type` function, which is the same as the exsting `elementSize` function. Before this diff, `sizeof_scalar_type` did the "unsupported" checks that have now moved.
- Add an `isValid()` function to let users of `ScalarType` know whether a given enum value is legit. This makes it possible to avoid the fatal error when calling `elementSize` on a bad value.
- Add unit tests for the new `isValid()`.

Differential Revision: D52451738
dbort added a commit to dbort/executorch that referenced this pull request Jan 3, 2024
Summary:

Fail non-fatally when encountering an unknown/unhandled `ScalarType` in a `.pte` file. As part of this:
- Move the "types not supported yet" logic out of `scalar_type_util` and into `tensor_parser`, since that decision is an aspect of the runtime and not a fundamental aspect of `ScalarType`.
- Remove the now-duplicate `sizeof_scalar_type` function, which is the same as the exsting `elementSize` function. Before this diff, `sizeof_scalar_type` did the "unsupported" checks that have now moved.
- Add an `isValid()` function to let users of `ScalarType` know whether a given enum value is legit. This makes it possible to avoid the fatal error when calling `elementSize` on a bad value.
- Add unit tests for the new `isValid()`.

Differential Revision: D52451738
dbort added a commit to dbort/executorch that referenced this pull request Jan 3, 2024
Summary:

Fail non-fatally when encountering an unknown/unhandled `ScalarType` in a `.pte` file. As part of this:
- Move the "types not supported yet" logic out of `scalar_type_util` and into `tensor_parser`, since that decision is an aspect of the runtime and not a fundamental aspect of `ScalarType`.
- Remove the now-duplicate `sizeof_scalar_type` function, which is the same as the exsting `elementSize` function. Before this diff, `sizeof_scalar_type` did the "unsupported" checks that have now moved.
- Add an `isValid()` function to let users of `ScalarType` know whether a given enum value is legit. This makes it possible to avoid the fatal error when calling `elementSize` on a bad value.
- Add unit tests for the new `isValid()`.

Differential Revision: D52451738
dbort added a commit to dbort/executorch that referenced this pull request Jan 3, 2024
Summary:

Fail non-fatally when encountering an unknown/unhandled `ScalarType` in a `.pte` file. As part of this:
- Move the "types not supported yet" logic out of `scalar_type_util` and into `tensor_parser`, since that decision is an aspect of the runtime and not a fundamental aspect of `ScalarType`.
- Remove the now-duplicate `sizeof_scalar_type` function, which is the same as the exsting `elementSize` function. Before this diff, `sizeof_scalar_type` did the "unsupported" checks that have now moved.
- Add an `isValid()` function to let users of `ScalarType` know whether a given enum value is legit. This makes it possible to avoid the fatal error when calling `elementSize` on a bad value.
- Add unit tests for the new `isValid()`.

Differential Revision: D52451738
dbort added a commit to dbort/executorch that referenced this pull request Jan 3, 2024
Summary:

Fail non-fatally when encountering an unknown/unhandled `ScalarType` in a `.pte` file. As part of this:
- Move the "types not supported yet" logic out of `scalar_type_util` and into `tensor_parser`, since that decision is an aspect of the runtime and not a fundamental aspect of `ScalarType`.
- Remove the now-duplicate `sizeof_scalar_type` function, which is the same as the exsting `elementSize` function. Before this diff, `sizeof_scalar_type` did the "unsupported" checks that have now moved.
- Add an `isValid()` function to let users of `ScalarType` know whether a given enum value is legit. This makes it possible to avoid the fatal error when calling `elementSize` on a bad value.
- Add unit tests for the new `isValid()`.

Differential Revision: D52451738
dbort added a commit to dbort/executorch that referenced this pull request Jan 3, 2024
Summary:

Fail non-fatally when encountering an unknown/unhandled `ScalarType` in a `.pte` file. As part of this:
- Move the "types not supported yet" logic out of `scalar_type_util` and into `tensor_parser`, since that decision is an aspect of the runtime and not a fundamental aspect of `ScalarType`.
- Remove the now-duplicate `sizeof_scalar_type` function, which is the same as the exsting `elementSize` function. Before this diff, `sizeof_scalar_type` did the "unsupported" checks that have now moved.
- Add an `isValid()` function to let users of `ScalarType` know whether a given enum value is legit. This makes it possible to avoid the fatal error when calling `elementSize` on a bad value.
- Add unit tests for the new `isValid()`.

Differential Revision: D52451738
dbort added a commit to dbort/executorch that referenced this pull request Jan 3, 2024
Summary:

Fail non-fatally when encountering an unknown/unhandled `ScalarType` in a `.pte` file. As part of this:
- Move the "types not supported yet" logic out of `scalar_type_util` and into `tensor_parser`, since that decision is an aspect of the runtime and not a fundamental aspect of `ScalarType`.
- Remove the now-duplicate `sizeof_scalar_type` function, which is the same as the exsting `elementSize` function. Before this diff, `sizeof_scalar_type` did the "unsupported" checks that have now moved.
- Add an `isValid()` function to let users of `ScalarType` know whether a given enum value is legit. This makes it possible to avoid the fatal error when calling `elementSize` on a bad value.
- Add unit tests for the new `isValid()`.

Differential Revision: D52451738
dbort added a commit to dbort/executorch that referenced this pull request Jan 3, 2024
Summary:

Fail non-fatally when encountering an unknown/unhandled `ScalarType` in a `.pte` file. As part of this:
- Move the "types not supported yet" logic out of `scalar_type_util` and into `tensor_parser`, since that decision is an aspect of the runtime and not a fundamental aspect of `ScalarType`.
- Remove the now-duplicate `sizeof_scalar_type` function, which is the same as the exsting `elementSize` function. Before this diff, `sizeof_scalar_type` did the "unsupported" checks that have now moved.
- Add an `isValid()` function to let users of `ScalarType` know whether a given enum value is legit. This makes it possible to avoid the fatal error when calling `elementSize` on a bad value.
- Add unit tests for the new `isValid()`.

Differential Revision: D52451738
@facebook-github-bot
Copy link
Contributor

This pull request has been merged in 89958d2.

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 Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported Merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants