@@ -305,7 +305,7 @@ public void writeTree(TreeNode root) throws Exception {
305305 outStringsStream .close ();
306306 writeInt (0 , outValueStream );
307307
308- final int array_offset = 1000 * 1000 * 1000 ;
308+ final int array_offset = Integer . MAX_VALUE ; // 2147483647, which is half of uint32
309309
310310 d .push (root );
311311 while (!d .isEmpty ()) {
@@ -328,6 +328,10 @@ public void writeTree(TreeNode root) throws Exception {
328328 throw new Exception ("should not happen" );
329329 }
330330
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+
331335 d .addAll (n .children );
332336 }
333337
@@ -339,7 +343,7 @@ public void writeTree(TreeNode root) throws Exception {
339343 TreeNode n = d .pollFirst ();
340344
341345 if (n .arrayElement != null ) {
342- n .offsetValue = array_offset + n .arrayElement .id ;
346+ n .offsetValue = array_offset + Short . toUnsignedInt ( n .arrayElement .id ) ;
343347 }
344348
345349 if (!n .children .isEmpty ()) {
@@ -387,6 +391,8 @@ public void writeTree(TreeNode root) throws Exception {
387391 obj .addProperty ("id" , Short .toUnsignedInt (n .id ));
388392 obj .addProperty ("nextSiblingId" , Short .toUnsignedInt (n .nextSiblingId ));
389393 obj .addProperty ("firstChildId" , Short .toUnsignedInt (n .firstChildId ));
394+ obj .addProperty ("offsetName" , Integer .toUnsignedLong (n .offsetName ));
395+ obj .addProperty ("offsetValue" , Integer .toUnsignedLong (n .offsetValue ));
390396 obj .addProperty ("name" , n .getName ());
391397 obj .addProperty ("nodeType" , n .nodeType );
392398 rootArray .add (obj );
0 commit comments