@@ -1286,8 +1286,12 @@ static char **NpyArr_encodeLabels(PyArrayObject *labels, PyObjectEncoder *enc,
1286
1286
} else {
1287
1287
int size_of_cLabel = 21 ; // 21 chars for int 64
1288
1288
cLabel = PyObject_Malloc (size_of_cLabel );
1289
- snprintf (cLabel , size_of_cLabel , "%" NPY_DATETIME_FMT ,
1290
- NpyDateTimeToEpoch (i8date , base ));
1289
+ if (scaleNanosecToUnit (& i8date , base ) == -1 ) {
1290
+ NpyArr_freeLabels (ret , num );
1291
+ ret = 0 ;
1292
+ break ;
1293
+ }
1294
+ snprintf (cLabel , size_of_cLabel , "%" NPY_DATETIME_FMT , i8date );
1291
1295
len = strlen (cLabel );
1292
1296
}
1293
1297
}
@@ -1373,7 +1377,7 @@ static void Object_beginTypeContext(JSOBJ _obj, JSONTypeContext *tc) {
1373
1377
tc -> prv = pc ;
1374
1378
1375
1379
if (PyTypeNum_ISDATETIME (enc -> npyType )) {
1376
- const int64_t longVal = * (npy_int64 * )enc -> npyValue ;
1380
+ int64_t longVal = * (npy_int64 * )enc -> npyValue ;
1377
1381
if (longVal == get_nat ()) {
1378
1382
tc -> type = JT_NULL ;
1379
1383
} else {
@@ -1389,7 +1393,10 @@ static void Object_beginTypeContext(JSOBJ _obj, JSONTypeContext *tc) {
1389
1393
tc -> type = JT_UTF8 ;
1390
1394
} else {
1391
1395
NPY_DATETIMEUNIT base = ((PyObjectEncoder * )tc -> encoder )-> datetimeUnit ;
1392
- pc -> longValue = NpyDateTimeToEpoch (longVal , base );
1396
+ if (scaleNanosecToUnit (& longVal , base ) == -1 ) {
1397
+ goto INVALID ;
1398
+ }
1399
+ pc -> longValue = longVal ;
1393
1400
tc -> type = JT_LONG ;
1394
1401
}
1395
1402
}
0 commit comments