@@ -305,7 +305,7 @@ public void writeTree(TreeNode root) throws Exception {
305
305
outStringsStream .close ();
306
306
writeInt (0 , outValueStream );
307
307
308
- final int array_offset = 1000 * 1000 * 1000 ;
308
+ final int array_offset = Integer . MAX_VALUE ; // 2147483647, which is half of uint32
309
309
310
310
d .push (root );
311
311
while (!d .isEmpty ()) {
@@ -328,6 +328,10 @@ public void writeTree(TreeNode root) throws Exception {
328
328
throw new Exception ("should not happen" );
329
329
}
330
330
331
+ if ((n .nodeType & TreeNode .Array ) != TreeNode .Array && Integer .toUnsignedLong (n .offsetValue ) >= Integer .toUnsignedLong (array_offset )) {
332
+ throw new Exception ("Non-array metadata has overflown array space. Please report this issue." );
333
+ }
334
+
331
335
d .addAll (n .children );
332
336
}
333
337
@@ -339,7 +343,7 @@ public void writeTree(TreeNode root) throws Exception {
339
343
TreeNode n = d .pollFirst ();
340
344
341
345
if (n .arrayElement != null ) {
342
- n .offsetValue = array_offset + n .arrayElement .id ;
346
+ n .offsetValue = array_offset + Short . toUnsignedInt ( n .arrayElement .id ) ;
343
347
}
344
348
345
349
if (!n .children .isEmpty ()) {
@@ -387,6 +391,8 @@ public void writeTree(TreeNode root) throws Exception {
387
391
obj .addProperty ("id" , Short .toUnsignedInt (n .id ));
388
392
obj .addProperty ("nextSiblingId" , Short .toUnsignedInt (n .nextSiblingId ));
389
393
obj .addProperty ("firstChildId" , Short .toUnsignedInt (n .firstChildId ));
394
+ obj .addProperty ("offsetName" , Integer .toUnsignedLong (n .offsetName ));
395
+ obj .addProperty ("offsetValue" , Integer .toUnsignedLong (n .offsetValue ));
390
396
obj .addProperty ("name" , n .getName ());
391
397
obj .addProperty ("nodeType" , n .nodeType );
392
398
rootArray .add (obj );
0 commit comments