diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2022-05-04 13:51:22 +0200 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2022-05-04 16:00:51 +0200 |
| commit | 0aee91ca299ec9f3ccebe106deb217b80d225cba (patch) | |
| tree | e33072d3c67fa935e54c60c8dbdd2514e083f7cc /gui | |
| parent | e130e04448327369be97929c28032dacd0a8e2ab (diff) | |
| download | mullvadvpn-0aee91ca299ec9f3ccebe106deb217b80d225cba.tar.xz mullvadvpn-0aee91ca299ec9f3ccebe106deb217b80d225cba.zip | |
Fix parsing of exe-headers when string size is in bytes
Diffstat (limited to 'gui')
| -rw-r--r-- | gui/src/main/windows-split-tunneling.ts | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/gui/src/main/windows-split-tunneling.ts b/gui/src/main/windows-split-tunneling.ts index 00c316ca79..fc6e5d87d9 100644 --- a/gui/src/main/windows-split-tunneling.ts +++ b/gui/src/main/windows-split-tunneling.ts @@ -559,13 +559,25 @@ async function parseStrings( let currentStringOffset = stringsOffset; while (currentStringOffset < stringTableEnd) { const stringValue = await Value.fromFile(fileHandle, currentStringOffset, STRING_TABLE_STRING); + const structSize = stringValue.get('wLength').value(); const valueSize = (stringValue.get('wValueLength').value() - 1) * 2; const szKeyOffset = currentStringOffset + stringValue.size; const { value: szKey, endOffset } = await readString(fileHandle, szKeyOffset, 'ucs2'); const valueOffset = alignDword(endOffset); - const { buffer } = await fileHandle.read(Buffer.alloc(valueSize), 0, valueSize, valueOffset); + // Some programs specify the value size in bytes instead of words resulting in reading double + // the length. To make sure we don't read beyond the end offset we calculate the max size to + // read. The last value is the null termination character. + const calculatedValueMaxSize = structSize - (valueOffset - currentStringOffset) - 2; + const valueReadSize = Math.min(valueSize, calculatedValueMaxSize); + + const { buffer } = await fileHandle.read( + Buffer.alloc(valueReadSize), + 0, + valueReadSize, + valueOffset, + ); const value = buffer.toString('ucs2'); strings.set(szKey, value); |
