mhoopmann / mstoolkit

Automatically exported from code.google.com/p/mstoolkit
27 stars 10 forks source link

Reading instrument name #24

Closed vdemichev closed 2 months ago

vdemichev commented 2 months ago

Hi Michael,

First, many thanks for a fantastic library!

I found something which seems to cause a crash when processing certain .raw files. https://github.com/vdemichev/DiaNN/discussions/973

MSReader.cpp:

cRAW.getInstrument(&sInstrument[0]);
cRAW.getManufacturer(&sManufacturer[0]);

RawReader.cpp:

void RAWReader::getInstrument(char* str){
  strcpy(str,rawInstrument);
}

sInstrument and sManufacturer are initialised with "unknown". What happens then if rawInstrument is longer than the capacity of sInstrument std::string?

I've so far applied a quick fix, adding this

sInstrument.reserve(512);
sManufacturer.reserve(512);

after each occurrence of

sInstrument="unknown";
sManufacturer="unknown";

Seems to resolve the issue (no longer crashes), but I guess there is likely a better more elegant way to fix this.

Best, Vadim

mhoopmann commented 2 months ago

Hi Vadim, Thanks for reporting the bug. Indeed, that is old, poorly written code. I'll have a fix in place soon. Cheers, Mike

mhoopmann commented 2 months ago

Should be resolved now. Thanks again for reporting the issue!