fix overflow problems

[Fixes #41921279]