Skip to content

Commit

Permalink
Don't left-shift negative values to fix UBSAN warning
Browse files Browse the repository at this point in the history
Instead, make the value positive, do the left-shift then, and make the
result negative again afterwards:

```
    ../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
    4creators#3 0x7f0cc5b82102 in PKImageDecode_Copy_WMP ../3rdParty/jxrlib/jxrgluelib/JXRGlueJxr.c:1874
```

Considering that the tests still pass, I think this is a safe solution
to this warning.
  • Loading branch information
milianw committed Jun 7, 2021
1 parent a684f95 commit 608803a
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions image/decode/segdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -961,8 +961,9 @@ Int DecodeMacroblockLowpass (CWMImageStrCodec * pSC, CCodingContext *pContext,
pCoeffs[k] += getBits (pIO, iModelBits);
}
else if (pCoeffs[k] < 0) {
pCoeffs[k] <<= iModelBits;
pCoeffs[k] -= getBits (pIO, iModelBits);
// left-shift the positive value and set the negative sign back afterwards
pCoeffs[k] = -(-pCoeffs[k] << iModelBits);
pCoeffs[k] -= getBits(pIO, iModelBits);
}
#endif // WIN32
else {
Expand Down

0 comments on commit 608803a

Please sign in to comment.