@@ -162,8 +162,10 @@ bool SpecFile::load_from_phd( std::istream &input )
162
162
163
163
const float upper_energy = (fields.size ()>1 && fields[1 ]>500 .0f && fields[1 ]<13000 .0f ) ? fields[1 ] : 0 .0f ;
164
164
const size_t nchannel = static_cast <size_t >( fields[0 ] );
165
- auto counts = std::make_shared< vector<float > >(nchannel,0 .0f );
165
+ if ( (nchannel < 1 ) || (nchannel > 1024 *65536 ) )
166
+ throw runtime_error ( " Invalid number of channels (" + std::to_string (nchannel) + " )" );
166
167
168
+ auto counts = std::make_shared< vector<float > >(nchannel,0 .0f );
167
169
168
170
size_t last_channel = 0 ;
169
171
while ( SpecUtils::safe_get_line (input, line, max_len) )
@@ -187,7 +189,7 @@ bool SpecFile::load_from_phd( std::istream &input )
187
189
188
190
const size_t start_channel = static_cast <size_t >( fields[0 ] );
189
191
190
- if ( (start_channel <= last_channel) || (start_channel > nchannel) )
192
+ if ( (last_channel != 0 ) && (( start_channel <= last_channel) || (start_channel > nchannel) ) )
191
193
throw runtime_error ( " Channels not ordered as expected" );
192
194
193
195
// We'll let the fuzzing test give us out-of-order channels, but otherwise require the file
@@ -269,9 +271,9 @@ bool SpecFile::load_from_phd( std::istream &input )
269
271
measurements_.push_back ( meas );
270
272
271
273
cleanup_after_load ();
272
- }catch ( std::exception & )
274
+ }catch ( std::exception &e )
273
275
{
274
- // cerr << SRC_LOCATION << "caught: " << e.what() << endl;
276
+ cerr << " caught: " << e.what () << endl;
275
277
reset ();
276
278
input.clear ();
277
279
input.seekg ( orig_pos, ios::beg );
0 commit comments