@@ -1283,6 +1283,13 @@ sixel_quant_apply_palette(
1283
1283
goto end ;
1284
1284
}
1285
1285
1286
+ /* NOTE: diffuse_jajuni, diffuse_stucki, and diffuse_burkes reference at
1287
+ * minimum the position pos + width * 1 - 2, so width must be at least 2
1288
+ * to avoid underflow.
1289
+ * On the other hand, diffuse_fs and diffuse_atkinson
1290
+ * reference pos + width * 1 - 1, but since these functions are only called
1291
+ * when width >= 1, they do not cause underflow.
1292
+ */
1286
1293
if (depth != 3 ) {
1287
1294
f_diffuse = diffuse_none ;
1288
1295
} else {
@@ -1297,13 +1304,16 @@ sixel_quant_apply_palette(
1297
1304
f_diffuse = diffuse_fs ;
1298
1305
break ;
1299
1306
case SIXEL_DIFFUSE_JAJUNI :
1300
- f_diffuse = diffuse_jajuni ;
1307
+ /* fallback to diffuse_none if width < 2 */
1308
+ f_diffuse = width >= 2 ? diffuse_jajuni : diffuse_none ;
1301
1309
break ;
1302
1310
case SIXEL_DIFFUSE_STUCKI :
1303
- f_diffuse = diffuse_stucki ;
1311
+ /* fallback to diffuse_none if width < 2 */
1312
+ f_diffuse = width >= 2 ? diffuse_stucki : diffuse_none ;
1304
1313
break ;
1305
1314
case SIXEL_DIFFUSE_BURKES :
1306
- f_diffuse = diffuse_burkes ;
1315
+ /* fallback to diffuse_none if width < 2 */
1316
+ f_diffuse = width >= 2 ? diffuse_burkes : diffuse_none ;
1307
1317
break ;
1308
1318
case SIXEL_DIFFUSE_A_DITHER :
1309
1319
f_diffuse = diffuse_none ;
0 commit comments