Skip to content

Commit 56b7586

Browse files
alexmalyshevmeta-codesync[bot]
authored andcommitted
Stop crashing when parsing bad code size limits (#138)
Summary: The use of JIT_CHECK here means that importing the module will crash the entire process if a bad code size limit is passed in. Use JIT_THROW_IF() instead, this will be caught by cinderx_exec() and convert to a proper RuntimeError. Pull Request resolved: #138 Test Plan: `uv run pytest cinderx/PythonLib` no longer raises alerts on Fedora about `python3.14` crashes. Reviewed By: yoney Differential Revision: D114601511 Pulled By: alexmalyshev fbshipit-source-id: 39b7a3b2611f4cc85b31cf36d4f21c5911875012
1 parent 3a4c7e9 commit 56b7586

2 files changed

Lines changed: 6 additions & 13 deletions

File tree

cinderx/Jit/pyjit.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ size_t parse_sized_argument(const std::string& val) {
344344
// " 1024 k" should parse OK - so remove the space.
345345
std::remove_copy_if(
346346
val.begin(), val.end(), std::back_inserter(parsed), ::isspace);
347-
JIT_CHECK(!parsed.empty(), "Input string is empty");
347+
JIT_THROW_IF(parsed.empty(), "Input string is empty");
348348
static_assert(
349349
sizeof(decltype(std::stoull(parsed))) == sizeof(size_t),
350350
"stoull parses to size_t size");
@@ -371,12 +371,12 @@ size_t parse_sized_argument(const std::string& val) {
371371
size_t ret_value{0};
372372
auto p_last = parsed.data() + parsed.size();
373373
auto int_ok = std::from_chars(parsed.data(), p_last, ret_value);
374-
JIT_CHECK(
375-
int_ok.ec == std::errc() && int_ok.ptr == p_last,
374+
JIT_THROW_IF(
375+
int_ok.ec != std::errc() || int_ok.ptr != p_last,
376376
"Invalid unsigned integer in input string: '{}'",
377377
val);
378-
JIT_CHECK(
379-
ret_value <= (std::numeric_limits<size_t>::max() / scale),
378+
JIT_THROW_IF(
379+
ret_value > (std::numeric_limits<size_t>::max() / scale),
380380
"Unsigned Integer overflow in input string: '{}'",
381381
val);
382382
return ret_value * scale;

cinderx/PythonLib/test_cinderx/test_jit_max_size.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
``max_code_size`` also has a runtime setter, exercised in-process.
1818
"""
1919

20-
import signal
2120
import subprocess
2221
import sys
2322
import tempfile
@@ -38,7 +37,6 @@
3837
_TINY_HIR_BLOCKS_LIMIT = "jit-max-hir-blocks=1"
3938
_TINY_LIR_INSTRS_LIMIT = "jit-max-lir-instrs=1"
4039
_TINY_LIR_BLOCKS_LIMIT = "jit-max-lir-blocks=1"
41-
_WINDOWS_STATUS_STACK_BUFFER_OVERRUN = 0xC0000409
4240

4341
# A trivial straight-line function: >1 instruction, 1 basic block (HIR or LIR).
4442
_STRAIGHT_LINE = """
@@ -306,12 +304,7 @@ def run_proc(size: str) -> str:
306304
encoding=ENCODING,
307305
env=subprocess_env(),
308306
)
309-
expected_returncode = (
310-
_WINDOWS_STATUS_STACK_BUFFER_OVERRUN
311-
if sys.platform == "win32"
312-
else -signal.SIGABRT
313-
)
314-
self.assertEqual(proc.returncode, expected_returncode, proc)
307+
self.assertNotEqual(proc.returncode, 0, proc)
315308
return proc.stderr
316309

317310
self.assertIn(

0 commit comments

Comments
 (0)