Description: Fix config file parsing heap corruption . - Either this was just always silently failing or the compilers somehow dealt with large `char` types - Converting from single byte char to UTF32 requires four times as much space, thus the output needs to be that size - Parser now also better deals with comments and empty lines Origin: upstream, https://github.com/thelaui/M.A.R.S./commit/a8a3f86b8b7ade5cae9fbf9c8b3839c7f0b312d0 Author: Lukas Dürrenberger --- This patch header follows DEP-3: http://dep.debian.net/deps/dep3/ --- a/src/Media/file.cpp +++ b/src/Media/file.cpp @@ -37,9 +37,19 @@ namespace file { // Play with all the lines in the file while (std::getline(fileStream, line, '\n')) { ++ lineCount; + + // ignore empty lines + if (line.empty()) + continue; + + // ignore comment lines + if (line.size() >= 2 && (line[0] == 47 && line[1] == 47)) + continue; + // remove '\r' at end of lines, when file has a CR LF EOL (windows...) if (*(line.end()-1) == '\r') line.erase(line.end()-1); + // Convert it to utf-32 int inSize = line.size(); std::vector logical(inSize); @@ -50,17 +60,15 @@ namespace file { FriBidiParType base = FRIBIDI_PAR_LTR; fribidi_log2vis(logical.data(), outSize, &base, visual.data(), NULL, NULL, NULL); - std::vector outstring(outSize); + std::vector outstring(outSize * 4, 0); fribidi_unicode_to_charset(FRIBIDI_CHAR_SET_UTF8, visual.data(), outSize, outstring.data()); - line = std::string(outstring.begin(), outstring.end()); + line = std::string(outstring.data()); std::basic_string utf32line; sf::Utf8::toUtf32(line.begin(), line.end(), back_inserter(utf32line)); - - // ignore comments and nearly empty lines - if(utf32line.size() > 2 && (utf32line[0] != 47 && utf32line[1] != 47)) - strings.push_back(utf32line); + + strings.push_back(utf32line); } fileStream.close(); }