You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
UBSan: unbounded shift in mif_decode() from MIF component prec (mif_cod.c) #433
Affected: JasPer 4.2.9 (5ce57f67e0011e0d2483992a5d77a092b1b64eb7) Sanitizer: UndefinedBehaviorSanitizer (shift exponent 917737015 is too large for 32-bit type 'int'), not ASan Entry point:imginfo -f poc.mif Build note: MIF is off by default. This needs -DJAS_ENABLE_MIF_CODEC=ON.
Summary
mif_decode() parses prec= from the MIF text header into cmpt->prec with no upper bound. If sgnd is set it does:
bias=1 << (cmpt->prec-1); /* mif_cod.c:239 */
The PoC uses prec=88888888888888888, which becomes a huge int; prec - 1 is then used as a shift count and UBSan reports a shift exponent of 917737015.
I did not find an existing GitHub issue for this site. This path is only compiled when the MIF codec is enabled.
Code
if (cmpt->sgnd) {
bias=1 << (cmpt->prec-1);
for (y=0; y<cmpt->height; ++y) {
for (x=0; x<cmpt->width; ++x) {
*jas_seq2d_getref(data, x, y) -=bias;
}
}
}
prec comes from the MIF component ... prec=N sgnd=1 line.
mif_cod.c:239:13: runtime error: shift exponent 917737015 is too large for 32-bit type 'int'
#0 mif_decode mif_cod.c:239:13
#1 jas_image_decode jas_image.c:477:16
#2 main imginfo.c:334:16
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior .../mif_cod.c:239:13
Suggested fix
Reject prec outside a sane range (e.g. 1..32) when parsing the MIF component header, before the shift. Use an unsigned type for the shift if a large prec is ever intended.
Activity