[Bug]: `compile()` with unrecognised flags raises a `ValueError` whose message crashes with `NullPointerException`
Los mantenedores suelen responder en 1 día
Ya se ha fusionado un pull request relacionado.
- #1232 de @jseop-lim — fusionado
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 35/100
Línea de trabajo
Start in graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java at CompileNode.checkFlags, then compare its raiseStatic call with the adjacent checkOptimize path and read the exception formatting path in ExceptionNodes.java. Reproduce with the supplied Python snippet and confirm that reading the caught ValueError message no longer crashes and matches compile(): unrecognised flags; check for a regression test covering the case.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Describe the bug
compile() with an unrecognised flags value raises a ValueError that can be caught, but reading its message (str(e), repr(e) or e.args) throws a Java NullPointerException and terminates the process.
Operating system
Linux
CPU architecture
x86_64
GraalPy version
25.0.2 (Python 3.12.8); also reproduced on 25.4.4.1.1 (Python 3.13.14) and on master 7e7182b103
JDK version
No response
Context configuration
No response
Steps to reproduce
try:
compile('1', 'f', 'exec', 0x7fffffff)
except ValueError as e:
print(e)
GraalPy master prints nothing and exits with the NullPointerException below (exit status 1; 25.0.2 exits with status 0).
Expected behavior
CPython 3.12.13 (same on 3.13.16):
compile(): unrecognised flags
Stack trace
java.lang.NullPointerException: Cannot invoke "com.oracle.truffle.api.strings.TruffleString.toJavaStringUncached()" because "format" is null
at org.graalvm.py/com.oracle.graal.python.builtins.objects.exception.ExceptionNodes$GetArgsNode.getFormattedMessage(ExceptionNodes.java:371)
at org.graalvm.py/com.oracle.graal.python.builtins.objects.exception.ExceptionNodes$GetArgsNode.doManaged(ExceptionNodes.java:396)
at org.graalvm.py/com.oracle.graal.python.builtins.objects.exception.ExceptionNodesFactory$GetArgsNodeGen$Inlined.executeAndSpecialize(ExceptionNodesFactory.java:1951)
at org.graalvm.py/com.oracle.graal.python.builtins.objects.exception.ExceptionNodesFactory$GetArgsNodeGen$Inlined.execute(ExceptionNodesFactory.java:1934)
at org.graalvm.py/com.oracle.graal.python.builtins.objects.exception.BaseExceptionBuiltins$StrNode.str(BaseExceptionBuiltins.java:511)
Additional context
The same crash happens for a bytes source, a negative flags, and the generic path (compile(None, 'f', 'exec', 0x10000)).
Root Cause
CompileNode.checkFlags raises with PRaiseNode.raiseStatic(this, ValueError, null, NO_VALUE, ErrorMessages.UNRECOGNIZED_FLAGS, PythonUtils.EMPTY_OBJECT_ARRAY) (BuiltinFunctions.java#L1143-L1148). That binds to the raiseStatic(Node, type, TruffleString message, Object... formatArgs) overload (PRaiseNode.java#L107-L112), so the exception gets a null message format, and formatting it lazily fails in ExceptionNodes.java#L370-L371. CPython sets a plain message (bltinmodule.c#L757-L763).
Fix Suggestion
Use the message overload, PRaiseNode.raiseStatic(this, ValueError, ErrorMessages.UNRECOGNIZED_FLAGS), as checkOptimize next to it does.
- Lenguaje dominante
- Python
- Estrellas
- 1.7k
- Forks
- 163
- Merge medio
- 14 h 10 min
- PR fusionados (30 d)
- 56
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de oracle/graalpython
-
[Bug]: sys.flags.debug is 1 whenever optimization is offPosiblemente ocupada @hippi345 la tomó hace 7 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
oracle/graalpython#1213 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
oracle/graalpython#1105 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
oracle/graalpython#1102 ·
Los mantenedores suelen responder en 1 día
-
enhancement
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
oracle/graalpython#1217 ·
Los mantenedores suelen responder en 1 día
-
enhancement
Dificultad 4/5 3-5 días Aptitud para principiantes 54/100
oracle/graalpython#1212 ·
Los mantenedores suelen responder en 1 día
Todos los issues de oracle/graalpython
Issues similares
-
Dificultad 1/5 1-3 horas Aptitud para principiantes 85/100
WLAN-Pi/wlanpi-profiler#341 ·
Los mantenedores suelen responder en 1 día
-
Memory leak: the shared `validation_aborted_error` keeps every traceback it is raised throughPosiblemente ocupada @Fire162 la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
graphql-python/graphql-core#287 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 67/100
roman-corgi/ctc-dip#160 ·
Los mantenedores suelen responder en 1 día
-
type-bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
render_findings.py reads and writes in the host's default encoding, so findings.html breaks on a cp1252 Windows hostPosiblemente ocupada @Aaqibhafeezkhan la tomó hoy. Abiertobug good first issue mentored python size: XS up-for-grabs
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
dheerajjha/mcp-migrate#366 · 1 comentario ·
Los mantenedores suelen responder en 1 día