Skip to content

Commit

Permalink
Avoid left-shifting negative values to fix UBSAN warning
Browse files Browse the repository at this point in the history
Instead, shift as an unsigned value, then convert back to signed:

```
    ../3rdParty/jxrlib/image/decode/segdec.c:1081:36: runtime error: left shift of negative value -1
    #0 0x7f0cc5c997c8 in DecodeMacroblockLowpass ../3rdParty/jxrlib/image/decode/segdec.c:1081
    #1 0x7f0cc5c2f4f4 in processMacroblockDec ../3rdParty/jxrlib/image/decode/strdec.c:417
    #2 0x7f0cc5c881f8 in ImageStrDecDecode ../3rdParty/jxrlib/image/decode/strdec.c:4010
    #3 0x7f0cc5b82102 in PKImageDecode_Copy_WMP ../3rdParty/jxrlib/jxrgluelib/JXRGlueJxr.c:1874
```

Co-authored-by: Milian Wolff <[email protected]>
  • Loading branch information
bgilbert and milianw committed Dec 8, 2022
1 parent a684f95 commit 6538ccd
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion image/decode/segdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@ Int DecodeMacroblockLowpass (CWMImageStrCodec * pSC, CCodingContext *pContext,
pCoeffs[k] += getBits (pIO, iModelBits);
}
else if (pCoeffs[k] < 0) {
pCoeffs[k] <<= iModelBits;
pCoeffs[k] = (int) (((unsigned) pCoeffs[k]) << iModelBits);
pCoeffs[k] -= getBits (pIO, iModelBits);
}
#endif // WIN32
Expand Down

0 comments on commit 6538ccd

Please sign in to comment.