[Bug]: `compile()` with unrecognised flags raises a `ValueError` whose message crashes with `NullPointerException`
メンテナーはふだん 1 日以内に返信
関連するプルリクエストがすでにマージされています。
- #1232 @jseop-lim による — マージ済み
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 35/100
調査の方向性
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.
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- Python
- スター
- 1.7k
- フォーク
- 163
- 平均マージ
- 14時間 10分
- マージ済み PR(30日)
- 56
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
oracle/graalpython のほかの issue
-
[Bug]: sys.flags.debug is 1 whenever optimization is off対応中かも @hippi345 が 7 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
oracle/graalpython#1213 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
oracle/graalpython#1105 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
oracle/graalpython#1102 ·
メンテナーはふだん 1 日以内に返信
-
enhancement
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
oracle/graalpython#1217 ·
メンテナーはふだん 1 日以内に返信
-
enhancement
難易度 4/5 3〜5日 初心者へのやさしさ 54/100
oracle/graalpython#1212 ·
メンテナーはふだん 1 日以内に返信
oracle/graalpython の issue をすべて見る
似ている issue
-
type-bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
push_gh-pages fails on master branch on forks対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープンgood first issue infrastructure
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
kuznia-rdzeni/coreblocks#1135 ·
-
good first issue server
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
documentation priority: high
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
a-lex-s/mealie-telegram-bot#54 ·
メンテナーはふだん 1 日以内に返信