mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Fix interpolation/STRFMT overflow issues
Widths and fractional widths greater than 255 would overflow a uint8_t and wrap around to smaller values. Total formatted lengths greater than the avilable buffer size would overflow it and potentially corrupt memory. Fixes #830 Closes #831
This commit is contained in:
15
test/asm/format-truncation.asm
Normal file
15
test/asm/format-truncation.asm
Normal file
@@ -0,0 +1,15 @@
|
||||
num equ 42
|
||||
fix equ 123.456
|
||||
str equs "hello"
|
||||
|
||||
println "{#0260x:num}"
|
||||
println "{#-260x:num}"
|
||||
println "{0280.260f:fix}"
|
||||
println "{260s:str}"
|
||||
println "{-260s:str}"
|
||||
|
||||
println "<{#0260x:num}>"
|
||||
println "<{#-260x:num}>"
|
||||
println "<{0280.260f:fix}>"
|
||||
println "<{260s:str}>"
|
||||
println "<{-260s:str}>"
|
||||
35
test/asm/format-truncation.err
Normal file
35
test/asm/format-truncation.err
Normal file
@@ -0,0 +1,35 @@
|
||||
ERROR: format-truncation.asm(5):
|
||||
Formatted numeric value too long
|
||||
ERROR: format-truncation.asm(6):
|
||||
Formatted numeric value too long
|
||||
ERROR: format-truncation.asm(7):
|
||||
Fractional width 260 too long, limiting to 255
|
||||
ERROR: format-truncation.asm(7):
|
||||
Formatted numeric value too long
|
||||
ERROR: format-truncation.asm(8):
|
||||
Formatted string value too long
|
||||
ERROR: format-truncation.asm(9):
|
||||
Formatted string value too long
|
||||
ERROR: format-truncation.asm(11):
|
||||
Formatted numeric value too long
|
||||
warning: format-truncation.asm(11): [-Wlong-string]
|
||||
String constant too long
|
||||
ERROR: format-truncation.asm(12):
|
||||
Formatted numeric value too long
|
||||
warning: format-truncation.asm(12): [-Wlong-string]
|
||||
String constant too long
|
||||
ERROR: format-truncation.asm(13):
|
||||
Fractional width 260 too long, limiting to 255
|
||||
ERROR: format-truncation.asm(13):
|
||||
Formatted numeric value too long
|
||||
warning: format-truncation.asm(13): [-Wlong-string]
|
||||
String constant too long
|
||||
ERROR: format-truncation.asm(14):
|
||||
Formatted string value too long
|
||||
warning: format-truncation.asm(14): [-Wlong-string]
|
||||
String constant too long
|
||||
ERROR: format-truncation.asm(15):
|
||||
Formatted string value too long
|
||||
warning: format-truncation.asm(15): [-Wlong-string]
|
||||
String constant too long
|
||||
error: Assembly aborted (12 errors)!
|
||||
10
test/asm/format-truncation.out
Normal file
10
test/asm/format-truncation.out
Normal file
@@ -0,0 +1,10 @@
|
||||
$0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002a
|
||||
$2a
|
||||
123.45599365234375001369732334415661667551799560000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
hello
|
||||
hello
|
||||
<$0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002
|
||||
<$2a
|
||||
<123.4559936523437500136973233441566166755179956000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
< hell
|
||||
<hello
|
||||
4
test/asm/interpolation-overflow.asm
Normal file
4
test/asm/interpolation-overflow.asm
Normal file
@@ -0,0 +1,4 @@
|
||||
; It seems that \1 was the easiest way to notice the memory corruption that
|
||||
; resulted from this overflow
|
||||
x = 0
|
||||
{.99999999f:x}\1
|
||||
9
test/asm/interpolation-overflow.err
Normal file
9
test/asm/interpolation-overflow.err
Normal file
@@ -0,0 +1,9 @@
|
||||
ERROR: interpolation-overflow.asm(4):
|
||||
Fractional width 99999999 too long, limiting to 255
|
||||
ERROR: interpolation-overflow.asm(4):
|
||||
Formatted numeric value too long
|
||||
warning: interpolation-overflow.asm(4): [-Wlarge-constant]
|
||||
Precision of fixed-point constant is too large
|
||||
while expanding symbol "0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||
FATAL: interpolation-overflow.asm(4):
|
||||
Macro argument '\1' not defined
|
||||
0
test/asm/interpolation-overflow.out
Normal file
0
test/asm/interpolation-overflow.out
Normal file
Reference in New Issue
Block a user