alicevision / AliceVision

Photogrammetric Computer Vision Framework
http://alicevision.org
Other
2.91k stars 809 forks source link

[sfmDataIO] Fix unhandled exception when parsing images with large numbers in the filenames #1565

Closed cbentejac closed 9 months ago

cbentejac commented 9 months ago

Description

This PR fixes a crash that occurred in aliceVision_cameraInit when images whose filenames contained large numbers were imported. Indeed, the images' filenames were parsed, and if a number was found in them, it was converted from a string to a signed integer using std::stoi.

std::stoi throws an std::out_of_range exception if the provided string exceeds the maximum value for an integer (2147483647). When importing images, it is quite common to have images that contain numbers larger than an integer (images may be named with the date and time at which they were taken, for example), thus causing an unhandled error.

Instead of converting the string to a signed integer, this pull request converts it to an unsigned int using boost::lexical_cast, which will throw a boost::bad_lexical_cast if the conversion cannot be made. If that happens, the exception is caught and the number variable is not set, which is the behaviour when no number is detected in the filename.