Skip to content

Commit 784bc28

Browse files
committed
Fix missing check in _array_reconstructor
1 parent f3a66dc commit 784bc28

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ArrayModuleBuiltins.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ static Object reconstructCached(VirtualFrame frame, Object arrayType, TruffleStr
9999
@Exclusive @Cached PyObjectCallMethodObjArgs callDecode,
100100
@Exclusive @Cached ArrayBuiltins.FromBytesNode fromBytesNode,
101101
@Exclusive @Cached ArrayBuiltins.FromUnicodeNode fromUnicodeNode,
102+
@Exclusive @Cached TypeNodes.IsTypeNode isTypeNode,
102103
@Exclusive @Cached IsSubtypeNode isSubtypeNode,
103104
@Exclusive @Cached ArrayBuiltins.ByteSwapNode byteSwapNode,
104105
@Exclusive @Cached TruffleString.CodePointLengthNode lengthNode,
@@ -109,7 +110,8 @@ static Object reconstructCached(VirtualFrame frame, Object arrayType, TruffleStr
109110
if (format == null) {
110111
throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.BAD_TYPECODE);
111112
}
112-
return doReconstruct(frame, inliningTarget, arrayType, typeCode, cachedCode, bytes, callDecode, fromBytesNode, fromUnicodeNode, isSubtypeNode, byteSwapNode, formatProfile.profile(format),
113+
return doReconstruct(frame, inliningTarget, arrayType, typeCode, cachedCode, bytes, callDecode, fromBytesNode, fromUnicodeNode, isTypeNode, isSubtypeNode, byteSwapNode,
114+
formatProfile.profile(format),
113115
getInstanceShape, raiseNode);
114116
}
115117

@@ -119,6 +121,7 @@ static Object reconstruct(VirtualFrame frame, Object arrayType, TruffleString ty
119121
@Exclusive @Cached PyObjectCallMethodObjArgs callDecode,
120122
@Exclusive @Cached ArrayBuiltins.FromBytesNode fromBytesNode,
121123
@Exclusive @Cached ArrayBuiltins.FromUnicodeNode fromUnicodeNode,
124+
@Exclusive @Cached TypeNodes.IsTypeNode isTypeNode,
122125
@Exclusive @Cached IsSubtypeNode isSubtypeNode,
123126
@Exclusive @Cached ArrayBuiltins.ByteSwapNode byteSwapNode,
124127
@Exclusive @Cached TruffleString.CodePointLengthNode lengthNode,
@@ -129,14 +132,18 @@ static Object reconstruct(VirtualFrame frame, Object arrayType, TruffleString ty
129132
if (format == null) {
130133
throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.BAD_TYPECODE);
131134
}
132-
return doReconstruct(frame, inliningTarget, arrayType, typeCode, mformatCode, bytes, callDecode, fromBytesNode, fromUnicodeNode, isSubtypeNode, byteSwapNode, format, getInstanceShape,
135+
return doReconstruct(frame, inliningTarget, arrayType, typeCode, mformatCode, bytes, callDecode, fromBytesNode, fromUnicodeNode, isTypeNode, isSubtypeNode, byteSwapNode, format,
136+
getInstanceShape,
133137
raiseNode);
134138
}
135139

136140
private static Object doReconstruct(VirtualFrame frame, Node inliningTarget, Object arrayType, TruffleString typeCode, int mformatCode, PBytes bytes, PyObjectCallMethodObjArgs callDecode,
137-
ArrayBuiltins.FromBytesNode fromBytesNode, ArrayBuiltins.FromUnicodeNode fromUnicodeNode, IsSubtypeNode isSubtypeNode,
141+
ArrayBuiltins.FromBytesNode fromBytesNode, ArrayBuiltins.FromUnicodeNode fromUnicodeNode, TypeNodes.IsTypeNode isTypeNode, IsSubtypeNode isSubtypeNode,
138142
ArrayBuiltins.ByteSwapNode byteSwapNode, BufferFormat format,
139143
TypeNodes.GetInstanceShape getInstanceShape, PRaiseNode raiseNode) {
144+
if (!isTypeNode.execute(inliningTarget, arrayType)) {
145+
throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.FIRST_ARGUMENT_MUST_BE_A_TYPE_OBJECT_NOT_P, arrayType);
146+
}
140147
if (!isSubtypeNode.execute(arrayType, PythonBuiltinClassType.PArray)) {
141148
throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.N_NOT_SUBTYPE_OF_ARRAY, arrayType);
142149
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/ErrorMessages.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,7 @@ public abstract class ErrorMessages {
883883
public static final TruffleString BYTES_OR_INT_ADDR_EXPECTED_INSTEAD_OF_P = tsLiteral("bytes or integer address expected instead of %p instance");
884884
public static final TruffleString UNICODE_STR_OR_INT_ADDR_EXPECTED_INSTEAD_OF_P = tsLiteral("unicode string or integer address expected instead of %p instance");
885885
public static final TruffleString N_NOT_SUBTYPE_OF_ARRAY = tsLiteral("%n is not a subtype of array");
886+
public static final TruffleString FIRST_ARGUMENT_MUST_BE_A_TYPE_OBJECT_NOT_P = tsLiteral("first argument must be a type object, not %p");
886887
public static final TruffleString CANNOT_BE_CONVERTED_TO_POINTER = tsLiteral("cannot be converted to pointer");
887888
public static final TruffleString PY_OBJ_IS_NULL = tsLiteral("PyObject is NULL");
888889
public static final TruffleString OUT_OF_RANGE_FLOAT_NOT_JSON_COMPLIANT = tsLiteral("Out of range float values are not JSON compliant");

0 commit comments

Comments
 (0)