Skip to content

Commit c5fab17

Browse files
Prevent use of NaN with Oracle numbers since it produces corrupt data
(#91).
1 parent 9311ab9 commit c5fab17

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/Transforms.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,12 @@ static int PythonFloatToOracleNumber(
248248
sword status;
249249

250250
doubleValue = PyFloat_AS_DOUBLE(pythonValue);
251+
if (isnan(doubleValue)) {
252+
PyErr_SetString(g_DatabaseErrorException,
253+
"value is not a number (NaN) and cannot be used in Oracle "
254+
"numbers");
255+
return -1;
256+
}
251257
status = OCINumberFromReal(environment->errorHandle, &doubleValue,
252258
sizeof(double), oracleValue);
253259
return Environment_CheckForError(environment, status,

src/cx_Oracle.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,18 @@
1818
#include <datetime.h>
1919
#include <structmember.h>
2020
#include <time.h>
21+
#include <math.h>
2122
#include <oci.h>
2223
#include <orid.h>
2324
#include <xa.h>
2425

26+
// define isnan for older versions of Visual Studio which only define _isnan
27+
#ifdef _WIN32
28+
#ifndef isnan
29+
#define isnan _isnan
30+
#endif
31+
#endif
32+
2533
// validate OCI library
2634
#if !defined(OCI_MAJOR_VERSION) || (OCI_MAJOR_VERSION < 11) || \
2735
((OCI_MAJOR_VERSION == 11) && (OCI_MINOR_VERSION < 2))

0 commit comments

Comments
 (0)