Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix hang in TestStrings.test_index_of_symbolic_start_idx #453

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion claripy/backends/backend_z3.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import numbers
import operator
import os
import re
import signal
import sys
import threading
Expand Down Expand Up @@ -616,7 +617,8 @@ def _abstract_to_primitive(self, ctx, ast):
if op_name == "INTERNAL":
seq = z3.SeqRef(ast)
if seq.is_string():
return seq.as_string()
# Converts a Unicode escape sequence to the corresponding character.
return re.sub(r"\\u\{([0-9a-fA-F]+)\}", lambda match: chr(int(match.group(1), 16)), seq.as_string())
raise BackendError("Unable to abstract Z3 object to primitive")

def _abstract_bv_val(self, ctx, ast):
Expand Down
5 changes: 2 additions & 3 deletions tests/test_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,9 @@ def test_index_of_simplification(self):
self.assertEqual((), tuple(solver.constraints))
self.assertEqual((target_idx,), solver.eval(res, 2))

@unittest.skip("Usually hangs")
def test_index_of_symbolic_start_idx(self):
str_symb = claripy.StringS("symb_index_of", explicit_name=True)
start_idx = claripy.BVS("symb_start_idx", 32, explicit_name=True)
start_idx = claripy.BVS("symb_start_idx", 8, explicit_name=True)

solver = self.get_solver()

Expand All @@ -282,7 +281,7 @@ def test_index_of_symbolic_start_idx(self):
solver.add(res != -1)
solver.add(res < 38)
self.assertTrue(solver.satisfiable())
self.assertEqual({33, 34, 35, 36, 37}, set(solver.eval(res, 10)))
self.assertEqual({33, 34, 35, 36, 37}, set(solver.eval(res, 5)))

strs = solver.eval(str_symb, 10 if KEEP_TEST_PERFORMANT else 100)
for s in strs:
Expand Down
Loading