Skip to content

Fix overflow in incrementName for long numeric suffixes - #3146

Open
Mani7527 wants to merge 1 commit into
AcademySoftwareFoundation:mainfrom
Mani7527:fix/increment-name-overflow
Open

Mani7527 wants to merge 1 commit into
AcademySoftwareFoundation:mainfrom
Mani7527:fix/increment-name-overflow

Conversation

@Mani7527

Copy link
Copy Markdown

Fixes #3145.

incrementName() parses the numeric suffix of a name with std::stoi and adds one, which fails for large suffixes:

  • 2147483647 overflows an int, giving an invalid name such as node-2147483648.
  • A suffix too large for an int, such as node99999999999, throws std::out_of_range.

Both cases happen in Element::createValidChildName() when the requested name is already taken, and in CgltfLoader when mesh names repeat. Loading a glTF file whose mesh node dup99999999999 has two primitives throws on main.

This change increments the suffix as a string of digits, so it can be any length. Leading zeros are still dropped, as before (testName007 becomes testName8). It also casts to unsigned char before calling isdigit.

New checks in CoreUtil.cpp cover both cases and leading zeros. On macOS arm64 with MATERIALX_TEST_RENDER=OFF and without the Python bindings, all 109 tests pass. Without the change to Util.cpp, the "String utilities" test fails and the other 108 pass.

AI tools were used to find the problem and prepare the fix and this description.

incrementName parsed the numeric suffix of a name with std::stoi and
added one. A suffix of 2147483647 overflowed, producing an invalid name
such as "node-2147483648", and a suffix too large for an int threw
std::out_of_range. Element::createValidChildName hits both cases when
the requested name is already taken, and CgltfLoader hits them when
mesh names repeat.

Increment the suffix as a string of digits instead, keeping the
existing behavior of dropping leading zeros.
@linux-foundation-easycla

linux-foundation-easycla Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: Mani7527 / name: Manikesh (cf33bba)

This branch has not been deployed

No deployments
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.

incrementName overflows on long numeric suffixes

1 participant