Visitar URL original
Segfault when an optional value is passed to a Python-implemented function · Issue #113 · cel-expr/cel-python · GitHub
Skip to content

Segfault when an optional value is passed to a Python-implemented function #113

Description

@sfodje-ship

What happens

Passing a CEL optional to a function whose overload has a Python impl
kills the process (SIGSEGV, exit 139) before the function is called. The same
happens when the argument is a map holding an optional. A Python try cannot
catch it.

Reproduce

import sys
from cel_expr_python import cel
from cel_expr_python.ext import ext_optional

def show(x):
    return "ok"

env = cel.NewEnv(
    variables={"m": cel.Type.DYN},
    extensions=[ext_optional.ExtOptional()],
    functions=[cel.FunctionDecl("show", [
        cel.Overload("show_any", cel.Type.STRING, [cel.Type("any")], impl=show),
    ])],
)
act = env.Activation({"m": {"a": 1}})
print(env.compile("show(m)").eval(act).value(), flush=True)      # ok
print(env.compile(sys.argv[1]).eval(act).value(), flush=True)
Expression Result
show(m[?'a']) exit 139
show(optional.of(1)) exit 139
show({'k': optional.of(1)}) exit 139
show([optional.of(1)]) no crash: UNKNOWN: Unimplemented type: 17

Expected

An evaluation error, as the list case already gives, or the optional handed to
the function as a value.

Likely cause

CelValueToPyObject has no case for an optional and returns null with a
Python error set. PyCelFunctionAdapter::Invoke puts that null into the
argument tuple and calls the function without checking it.

Versions

cel-expr-python 0.1.3 from PyPI, and main at 45eefa7 built from source.
CPython 3.14.6, macOS arm64.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions