Skip to content

Commit

Permalink
Fix NaN normalization bug for packed tval
Browse files Browse the repository at this point in the history
NaN normalization check should use a full NaN check to decide when to
normalize, even when using partial NaN initialization.  The fix here
is to switch to full NaN initialization in general.
  • Loading branch information
svaarala committed Oct 12, 2020
1 parent 1827a77 commit 19312f8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src-input/duk_dblunion.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,8 @@ typedef union duk_double_union duk_double_union;
} while (0)

#define DUK__DBLUNION_NORMALIZE_NAN_CHECK_NOTFULL(u) do { \
if (DUK__DBLUNION_IS_NAN_NOTFULL((u))) { \
/* Check must be full. */ \
if (DUK__DBLUNION_IS_NAN_FULL((u))) { \
DUK__DBLUNION_SET_NAN_NOTFULL((u)); \
} \
} while (0)
Expand All @@ -334,12 +335,11 @@ typedef union duk_double_union duk_double_union;
*/

#if defined(DUK_USE_PACKED_TVAL)
#if defined(DUK_USE_FULL_TVAL)
#define DUK_DBLUNION_NORMALIZE_NAN_CHECK(u) DUK__DBLUNION_NORMALIZE_NAN_CHECK_FULL((u))
#define DUK_DBLUNION_IS_NAN(u) DUK__DBLUNION_IS_NAN_FULL((u))
#define DUK_DBLUNION_IS_NORMALIZED_NAN(u) DUK__DBLUNION_IS_NORMALIZED_NAN_FULL((u))
#define DUK_DBLUNION_SET_NAN(d) DUK__DBLUNION_SET_NAN_FULL((d))
#else
#if 0
#define DUK_DBLUNION_NORMALIZE_NAN_CHECK(u) DUK__DBLUNION_NORMALIZE_NAN_CHECK_NOTFULL((u))
#define DUK_DBLUNION_IS_NAN(u) DUK__DBLUNION_IS_NAN_NOTFULL((u))
#define DUK_DBLUNION_IS_NORMALIZED_NAN(u) DUK__DBLUNION_IS_NORMALIZED_NAN_NOTFULL((u))
Expand Down
19 changes: 19 additions & 0 deletions tests/ecmascript/test-bug-packed-tval-nan-normalize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*---
{
"custom": true
}
---*/

/*===
NaN
done
===*/

try {
var val = CBOR.decode(new Uint8Array([ 0xfb, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 ]));
print(val);
} catch (e) {
print(e.stack || e);
}

print('done');

0 comments on commit 19312f8

Please sign in to comment.