You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Not EOF if we are not at the end of the buffer.
if (myBufferIndex < myCurrentBufferSize)
{
// There are still available bytes in the buffer, so NOT EOF.
returnfalse;
}
else
{
if (myFileTypePtr == NULL)
{
// No myFileTypePtr, so not eof (return 0).
return0;
}
// exhausted our buffer, so check the file for eof.
return myFileTypePtr->eof();
}
}
It checks if myBufferIndex < myCurrentBufferSize, which will be false, and it thinks the file should continue being read from.
This can result in a seg fault depending on what you try to do with the buffer at that point, after you've tried to read another line (that doesn't exist) from the file.
Code sample:
#include"InputFile.h"
#include"StringBasics.h"
#include"StringArray.h"
#include<iostream>
#include<string>intmain(int argc, char *argv[]) {
std::string bad_filepath = argv[1];
IFILE test = ifopen(bad_filepath.c_str(), "r");
// This loop is roughly what RAREMETAL does when reading in a covariance filewhile (!ifeof(test)) {
String buffer;
buffer.ReadLine(test);
StringArray tokens;
tokens.AddTokens(buffer, "\t");
int p = tokens[0].Find("chr");
}
std::cout << "Finished";
return0;
}
Attached file, run with above code, will cause a seg fault.
The simple solution to this (if you're a user looking to get around this bug) is just add a zero somewhere it doesn't matter at the end of the file, or an extra space, and the file will be read successfully.
The text was updated successfully, but these errors were encountered:
I believe this library is deprecated, but wanted to leave this info for future reference in case someone else runs into this problem.
It seems as though ifeof() does not return true when the last line in the file fills the buffer exactly (to length DEFAULT_BUFFER_SIZE).
If you read through a file using String::readLine():
libStatGen/general/StringBasics.cpp
Lines 744 to 776 in fae4fca
It calls ifgetc() repeatedly:
libStatGen/general/InputFile.h
Lines 324 to 341 in fae4fca
When the last line fills the buffer exactly,
myBufferIndex == myCurrentBufferSize == DEFAULT_BUFFER_SIZE
.But when
ifeof()
checks to see if we have arrived at EOF:libStatGen/general/InputFile.h
Lines 386 to 404 in fae4fca
It checks if
myBufferIndex < myCurrentBufferSize
, which will be false, and it thinks the file should continue being read from.This can result in a seg fault depending on what you try to do with the buffer at that point, after you've tried to read another line (that doesn't exist) from the file.
Code sample:
Attached file, run with above code, will cause a seg fault.
The simple solution to this (if you're a user looking to get around this bug) is just add a zero somewhere it doesn't matter at the end of the file, or an extra space, and the file will be read successfully.
The text was updated successfully, but these errors were encountered: