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.
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 usingstd::stoi
.std::stoi
throws anstd::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 aboost::bad_lexical_cast
if the conversion cannot be made. If that happens, the exception is caught and thenumber
variable is not set, which is the behaviour when no number is detected in the filename.