Skip to content

Commit c51e690

Browse files
committed
Properly check arg types of ctx_CallTupleDict
1 parent 932902b commit c51e690

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyContextFunctions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2002,10 +2002,10 @@ Object execute(Object[] arguments,
20022002
@Cached HPyTransformExceptionToNativeNode transformExceptionToNativeNode) throws ArityException, UnsupportedTypeException {
20032003
checkArity(arguments, 4);
20042004
GraalHPyContext nativeContext = asContextNode.execute(arguments[0]);
2005-
Object callable = asPythonObjectNode.execute(nativeContext, arguments[1]);
20062005
try {
20072006
Object[] args = castArgsNode.execute(ensureHandleNode.execute(nativeContext, arguments[2]));
20082007
PKeyword[] keywords = castKwargsNode.execute(ensureHandleNode.execute(nativeContext, arguments[3]));
2008+
Object callable = asPythonObjectNode.execute(nativeContext, arguments[1]);
20092009
return asHandleNode.execute(nativeContext, callNode.execute(callable, args, keywords));
20102010
} catch (PException e) {
20112011
// transformExceptionToNativeNode acts as a branch profile

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyNodes.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2136,8 +2136,13 @@ static Object[] doNull(GraalHPyHandle argsHandle) {
21362136

21372137
@Specialization(guards = "!argsHandle.isNull()")
21382138
static Object[] doNotNull(GraalHPyHandle argsHandle,
2139-
@Cached ExecutePositionalStarargsInteropNode expandArgsNode) {
2140-
return expandArgsNode.executeWithGlobalState(argsHandle.getDelegate());
2139+
@Cached ExecutePositionalStarargsInteropNode expandArgsNode,
2140+
@Cached PRaiseNode raiseNode) {
2141+
Object args = argsHandle.getDelegate();
2142+
if (PGuards.isPTuple(args)) {
2143+
return expandArgsNode.executeWithGlobalState(args);
2144+
}
2145+
throw raiseNode.raise(TypeError, "HPy_CallTupleDict requires args to be a tuple or null handle");
21412146
}
21422147
}
21432148

@@ -2158,8 +2163,12 @@ static PKeyword[] doNoKeywords(GraalHPyHandle kwargsHandle,
21582163
static PKeyword[] doKeywords(@SuppressWarnings("unused") GraalHPyHandle kwargsHandle,
21592164
@Bind("kwargsHandle.getDelegate()") Object delegate,
21602165
@Shared("lenNode") @Cached @SuppressWarnings("unused") HashingCollectionNodes.LenNode lenNode,
2161-
@Cached ExpandKeywordStarargsNode expandKwargsNode) {
2162-
return expandKwargsNode.execute(delegate);
2166+
@Cached ExpandKeywordStarargsNode expandKwargsNode,
2167+
@Cached PRaiseNode raiseNode) {
2168+
if (PGuards.isDict(delegate)) {
2169+
return expandKwargsNode.execute(delegate);
2170+
}
2171+
throw raiseNode.raise(TypeError, "HPy_CallTupleDict requires kw to be a dict or null handle");
21632172
}
21642173

21652174
static boolean isEmptyDict(HashingCollectionNodes.LenNode lenNode, Object delegate) {

0 commit comments

Comments
 (0)