File: fix-config-file-parsing-heap-corruption.patch

package info (click to toggle)
marsshooter 0.7.6-9
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 80,812 kB
  • sloc: cpp: 20,216; xml: 29; makefile: 6
file content (56 lines) | stat: -rw-r--r-- 2,406 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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 <eXpl0it3r@my-gate.net>
---
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<FriBidiChar> 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<char> outstring(outSize);
+                std::vector<char> 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<sf::Uint32> 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();
         }