Skip to content

Commit a351d2b

Browse files
mnoiyxiaoxial
authored andcommitted
fix core dumped bug appear in stoi()
1 parent 29bdb3a commit a351d2b

1 file changed

Lines changed: 58 additions & 9 deletions

File tree

Library/Raisr.cpp

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,32 @@ static RNLERRORTYPE VerifyTrainedData(std::string input, std::string file_type,
170170
return RNLErrorNone;
171171
}
172172

173+
RNLERRORTYPE RNLStoi(unsigned int *pValue, const char *configContent, std::string configPath)
174+
{
175+
try
176+
{
177+
*pValue = std::stoi(configContent);
178+
return RNLErrorNone;
179+
}
180+
catch (const std::invalid_argument &ia)
181+
{
182+
std::cout << "[RAISR ERROR] configFile corrupted: " << configPath << std::endl;
183+
return RNLErrorBadParameter;
184+
}
185+
186+
catch (const std::out_of_range &oor)
187+
{
188+
std::cout << "[RAISR ERROR] configFile corrupted: " << configPath << std::endl;
189+
return RNLErrorBadParameter;
190+
}
191+
192+
catch (const std::exception &e)
193+
{
194+
std::cout << "[RAISR ERROR] configFile corrupted: " << configPath << std::endl;
195+
return RNLErrorBadParameter;
196+
}
197+
}
198+
173199
static RNLERRORTYPE ReadTrainedData(std::string hashtablePath, std::string QStrPath, std::string QCohPath, int pass)
174200
{
175201
if (pass == 2)
@@ -195,9 +221,21 @@ static RNLERRORTYPE ReadTrainedData(std::string hashtablePath, std::string QStrP
195221
std::istringstream filteriss(line);
196222
std::vector<std::string> filterTokens{std::istream_iterator<std::string>{filteriss},
197223
std::istream_iterator<std::string>{}};
198-
unsigned int hashkeySize = std::stoi(filterTokens[0].c_str());
199-
unsigned int pixelTypes = std::stoi(filterTokens[1].c_str());
200-
unsigned int rows = std::stoi(filterTokens[2].c_str());
224+
unsigned int hashkeySize;
225+
if (RNLErrorNone != RNLStoi(&hashkeySize, filterTokens[0].c_str(), hashtablePath))
226+
{
227+
return RNLErrorBadParameter;
228+
}
229+
unsigned int pixelTypes;
230+
if (RNLErrorNone != RNLStoi(&pixelTypes, filterTokens[1].c_str(), hashtablePath))
231+
{
232+
return RNLErrorBadParameter;
233+
}
234+
unsigned int rows;
235+
if (RNLErrorNone != RNLStoi(&rows, filterTokens[2].c_str(), hashtablePath))
236+
{
237+
return RNLErrorBadParameter;
238+
}
201239
int aligned_rows = 16 * (int)((rows + 15) / 16);
202240

203241
if (hashkeySize != gQuantizationAngle * gQuantizationStrength * gQuantizationCoherence)
@@ -1229,14 +1267,25 @@ RNLERRORTYPE RNLInit(std::string &modelPath,
12291267
std::cout << "[RAISR ERROR] configFile corrupted: " << configPath << std::endl;
12301268
return RNLErrorBadParameter;
12311269
}
1232-
1233-
gQuantizationAngle = std::stoi(configTokens[0].c_str());
1270+
if (RNLErrorNone != RNLStoi(&gQuantizationAngle, configTokens[0].c_str(), configPath))
1271+
{
1272+
return RNLErrorBadParameter;
1273+
}
12341274
gQAngle = gQuantizationAngle / PI;
1235-
gQuantizationStrength = std::stoi(configTokens[1].c_str());
1236-
gQuantizationCoherence = std::stoi(configTokens[2].c_str());
1275+
if (RNLErrorNone != RNLStoi(&gQuantizationStrength, configTokens[1].c_str(), configPath))
1276+
{
1277+
return RNLErrorBadParameter;
1278+
}
1279+
if (RNLErrorNone != RNLStoi(&gQuantizationCoherence, configTokens[2].c_str(), configPath))
1280+
{
1281+
return RNLErrorBadParameter;
1282+
}
1283+
12371284
// Varify hashtable file format
1238-
gPatchSize = std::stoi(configTokens[3].c_str());
1239-
;
1285+
if (RNLErrorNone != RNLStoi(&gPatchSize, configTokens[3].c_str(), configPath))
1286+
{
1287+
return RNLErrorBadParameter;
1288+
};
12401289
gPatchMargin = gPatchSize >> 1;
12411290
gLoopMargin = (gPatchSize >> 1) + 1;
12421291
gResizeExpand = (gLoopMargin + 2);

0 commit comments

Comments
 (0)