[Support] Fix overflow in SLEB128 decoding.
authorAhmed Bougacha <ahmed.bougacha@gmail.com>
Thu, 27 Apr 2017 02:09:44 +0000 (02:09 +0000)
committerAhmed Bougacha <ahmed.bougacha@gmail.com>
Thu, 27 Apr 2017 02:09:44 +0000 (02:09 +0000)
decodeULEB128 was fixed in r216268, but decodeSLEB128 always had the
same issue, which is now exposed in r301369.

llvm-svn: 301510

llvm/include/llvm/Support/LEB128.h

index a2bcef8..29640db 100644 (file)
@@ -160,7 +160,7 @@ inline int64_t decodeSLEB128(const uint8_t *p, unsigned *n = nullptr,
       return 0;
     }
     Byte = *p++;
-    Value |= ((Byte & 0x7f) << Shift);
+    Value |= (int64_t(Byte & 0x7f) << Shift);
     Shift += 7;
   } while (Byte >= 128);
   // Sign extend negative numbers.