commit: 1c83487c17de009fb6e57d275b98d3254261145b
parent 304a84419f73eb91f8c250c46f21b375b7777f96
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Sat, 13 May 2023 00:05:56 +0200
main: Fix pe_offset bounds check + bump buffer to 4096
Not harmful thanks to Hare but it would abort:
Abort: main.ha:98:6: slice or array access out of bounds
512 was previously chosen to avoid multiple low-level sector reads on
old storage but correct detection takes priority, specially as modern storage
uses 4096 bytes sectors.
Diffstat:
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/main.ha b/main.ha
@@ -74,7 +74,7 @@ const pe_magic: []u8 = ['P', 'E', 0x00, 0x00];
const racket: []u8 = ['r', 'a', 'c', 'k', 'e', 't'];
fn is_blob(filename: str) (bool | fs::error | io::error) = {
- static let buffer: [512]u8 = [0...];
+ static let buffer: [4096]u8 = [0...];
const file = os::open(filename)?;
defer io::close(file)!;
@@ -95,7 +95,7 @@ fn is_blob(filename: str) (bool | fs::error | io::error) = {
if (bytes::hasprefix(buffer, dos_magic)) {
const pe_offset = endian::legetu32(buffer[60..64]);
- if ((pe_offset < 512+4) && bytes::hasprefix(buffer[pe_offset..pe_offset+4], pe_magic)) {
+ if ((pe_offset <= 4096-4) && bytes::hasprefix(buffer[pe_offset..pe_offset+4], pe_magic)) {
return true;
};
};