Skip to content

Commit 114820f

Browse files
committed
Fix: argument validation in ctx_Bytes_FromStringAndSize
1 parent 42f2eb9 commit 114820f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.OverflowError;
4444
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.SystemError;
4545
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.TypeError;
46+
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.ValueError;
4647
import static com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyContextFunctions.FunctionMode.CHAR_PTR;
4748
import static com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyContextFunctions.FunctionMode.INT32;
4849
import static com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyContextFunctions.FunctionMode.OBJECT;
@@ -1261,10 +1262,16 @@ Object execute(Object[] arguments,
12611262
int size;
12621263
try {
12631264
if (withSize) {
1265+
if (interopLib.isNull(charPtr)) {
1266+
return raiseNode.raiseWithoutFrame(context, GraalHPyHandle.NULL_HANDLE, ValueError, "NULL char * passed to HPyBytes_FromStringAndSize");
1267+
}
12641268
size = castToJavaIntNode.execute(arguments[2]);
12651269
if (size == 0) {
12661270
return asHandleNode.execute(context, factory.createBytes(new byte[size]));
12671271
}
1272+
if (size < 0) {
1273+
return raiseNode.raiseWithoutFrame(context, GraalHPyHandle.NULL_HANDLE, SystemError, "negative size passed");
1274+
}
12681275
} else {
12691276
size = castToJavaIntNode.execute(callHelperNode.call(context, GraalHPyNativeSymbol.GRAAL_HPY_STRLEN, charPtr));
12701277
}
@@ -1281,7 +1288,7 @@ Object execute(Object[] arguments,
12811288
} catch (InteropException e) {
12821289
return raiseNode.raiseWithoutFrame(context, GraalHPyHandle.NULL_HANDLE, TypeError, "%m", e);
12831290
} catch (OverflowException e) {
1284-
return raiseNode.raiseWithoutFrame(context, GraalHPyHandle.NULL_HANDLE, SystemError, "negative size passed");
1291+
return raiseNode.raiseWithoutFrame(context, GraalHPyHandle.NULL_HANDLE, OverflowError, ErrorMessages.BYTE_STR_IS_TOO_LARGE);
12851292
}
12861293
}
12871294
}

0 commit comments

Comments
 (0)