Skip to content

[BugFix] Fix off-by-one error in the type index range check within Object::IsInstance() #17902

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ConvolutedDog
Copy link

This PR fixes an off-by-one error in the type index range check within Object::IsInstance(), an example and steps to reproduce it are at Issue #17901.

@ConvolutedDog
Copy link
Author

ConvolutedDog commented Apr 28, 2025

@liangfu @tqchen @wweic @cbalint13 @tkonolige @FrozenGene @eqy
Request for a review.

…nstance()

This PR fixes an off-by-one error in the type index range check within `Object::IsInstance()`.

Currently, the condition `self->type_index_ < end` is used to check if a type index falls within a reserved range (`[begin, end)`). However, since end is computed as `begin + _type_child_slots`, this means the range check excludes the last valid index `(end - 1)`.

Example:

If `begin = 500` and `_type_child_slots = 5`, then `end = 505`.
The current check (`500 <= type_index_ < 505`) only allows 500, 501, 502, ..., 504, but logically, 505 should also be included if `_type_child_slots` is meant to cover indices up to `begin + _type_child_slots`.
@ConvolutedDog ConvolutedDog force-pushed the ConvolutedDog-off-by-one-bug-fix branch from 8e2bd46 to f72c4f5 Compare April 29, 2025 13:29
@ConvolutedDog
Copy link
Author

@tqchen The arm/pr-head CI failed due to Jenkins agent disconnection. Could you please help trigger a rerun action? Thanks!

@cbalint13
Copy link
Contributor

@tvm-bot rerun

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants