Skip to content

Commit

Permalink
Fix operators.ORD for BitVecs of size > 8 (#1512)
Browse files Browse the repository at this point in the history
* Fix operators.ORD for BitVecs of size > 8

TLDR: `ORD(s)` should return something that has 8 bits instead of 7, which it incorrectly did for BitVecs with size>8.

Note that the `ORD` still does not support `BitVec`s with size<8, but I am not sure if we need that support for now. To be clear, such situation ends up as an assertion failure that is being done in `BitVecExtract`, so when assertions are gone (for optimized launches) we might want to extend `ORD` to support it.

* Add proper ORD fix testcase
  • Loading branch information
disconnect3d authored Aug 22, 2019
1 parent b2018e1 commit db07516
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion manticore/core/smtlib/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def ORD(s):
if s.size == 8:
return s
else:
return BitVecExtract(s, 0, 7)
return BitVecExtract(s, 0, 8)
elif isinstance(s, int):
return s & 0xFF
else:
Expand Down
9 changes: 9 additions & 0 deletions tests/other/test_smtlibv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,15 @@ def test_ORD(self):
self.assertTrue(solver.check(cs))
self.assertEqual(solver.get_value(cs, a), ord("Z"))

def test_ORD_proper_extract(self):
solver = Z3Solver.instance()
cs = ConstraintSet()
a = cs.new_bitvec(32)
cs.add(Operators.ORD(a) == Operators.ORD("\xff"))

self.assertTrue(solver.check(cs))
self.assertEqual(solver.get_value(cs, a), ord("\xff"))

def test_CHR(self):
solver = Z3Solver.instance()
cs = ConstraintSet()
Expand Down

0 comments on commit db07516

Please sign in to comment.