Skip to content

Commit 54792ba

Browse files
jcowgilldcommander
authored andcommitted
Fix MIPS DSPr2 4:2:0 upsample bug w/ small images
The DSPr2 code was errantly comparing the residual (t9, width & 0xF) with the end pointer (t4, out + width) instead of the width directly (a1). This would give the wrong results with any image whose output width was less than 16. The other small changes (ulw to lw and removal of the nop) are just some easy optimizations around this code. This issue caused a buffer overrun and subsequent segfault on images whose scaled output height was 1 pixel and whose scaled output width was < 16 pixels. Note that the "plain" (non-fancy and non-merged) upsample routine, which was affected by this bug, is normally not used except when decompressing a non-YCbCr JPEG image, but it is also used when decompressing a single-row image (because the other upsampling algorithms require at least two rows.) Closes flutter#16.
1 parent 498d9bc commit 54792ba

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

ChangeLog.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ Clang/LLVM optimizer uses load combining to transfer multiple adjacent 32-bit
2121
structure members into a single 64-bit register, and this exposed the ABI
2222
conformance issue.
2323

24+
[4] Fixed a bug in the MIPS DSPr2 4:2:0 "plain" (non-fancy and non-merged)
25+
upsampling routine that caused a buffer overflow (and subsequent segfault) when
26+
decompressing a 4:2:0 JPEG image whose scaled output width was less than 16
27+
pixels. The "plain" upsampling routines are normally only used when
28+
decompressing a non-YCbCr JPEG image, but they are also used when decompressing
29+
a JPEG image whose scaled output height is 1.
30+
2431

2532
1.4.1
2633
=====

simd/jsimd_mips_dspr2.S

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1811,12 +1811,11 @@ LEAF_MIPS_DSPR2(jsimd_h2v2_upsample_mips_dspr2)
18111811
bgtz t4, 2b
18121812
addiu t5, 2
18131813
3:
1814-
ulw t6, 0(t7) // t6 = outptr
1815-
ulw t5, 4(t7) // t5 = outptr[1]
1814+
lw t6, 0(t7) // t6 = outptr[0]
1815+
lw t5, 4(t7) // t5 = outptr[1]
18161816
addu t4, t6, a1 // t4 = new end address
1817-
subu t8, t4, t9
1818-
beqz t8, 5f
1819-
nop
1817+
beq a1, t9, 5f
1818+
subu t8, t4, t9
18201819
4:
18211820
ulw t0, 0(t6)
18221821
ulw t1, 4(t6)

0 commit comments

Comments
 (0)