43
43
import static com .oracle .graal .python .builtins .PythonBuiltinClassType .OverflowError ;
44
44
import static com .oracle .graal .python .builtins .PythonBuiltinClassType .SystemError ;
45
45
import static com .oracle .graal .python .builtins .PythonBuiltinClassType .TypeError ;
46
+ import static com .oracle .graal .python .builtins .PythonBuiltinClassType .ValueError ;
46
47
import static com .oracle .graal .python .builtins .objects .cext .hpy .GraalHPyContextFunctions .FunctionMode .CHAR_PTR ;
47
48
import static com .oracle .graal .python .builtins .objects .cext .hpy .GraalHPyContextFunctions .FunctionMode .INT32 ;
48
49
import static com .oracle .graal .python .builtins .objects .cext .hpy .GraalHPyContextFunctions .FunctionMode .OBJECT ;
@@ -1261,10 +1262,16 @@ Object execute(Object[] arguments,
1261
1262
int size ;
1262
1263
try {
1263
1264
if (withSize ) {
1265
+ if (interopLib .isNull (charPtr )) {
1266
+ return raiseNode .raiseWithoutFrame (context , GraalHPyHandle .NULL_HANDLE , ValueError , "NULL char * passed to HPyBytes_FromStringAndSize" );
1267
+ }
1264
1268
size = castToJavaIntNode .execute (arguments [2 ]);
1265
1269
if (size == 0 ) {
1266
1270
return asHandleNode .execute (context , factory .createBytes (new byte [size ]));
1267
1271
}
1272
+ if (size < 0 ) {
1273
+ return raiseNode .raiseWithoutFrame (context , GraalHPyHandle .NULL_HANDLE , SystemError , "negative size passed" );
1274
+ }
1268
1275
} else {
1269
1276
size = castToJavaIntNode .execute (callHelperNode .call (context , GraalHPyNativeSymbol .GRAAL_HPY_STRLEN , charPtr ));
1270
1277
}
@@ -1281,7 +1288,7 @@ Object execute(Object[] arguments,
1281
1288
} catch (InteropException e ) {
1282
1289
return raiseNode .raiseWithoutFrame (context , GraalHPyHandle .NULL_HANDLE , TypeError , "%m" , e );
1283
1290
} 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 );
1285
1292
}
1286
1293
}
1287
1294
}
0 commit comments