Fix buffer overrun in DDM heap upload.

The HPSG heap upload was using a 4KB buffer.  A test provided by an
external developer is creating massive arrays that need more than 12KB,
so we overran the buffer and trashed the native heap.

This change adds a test to prevent the overrun, and increases the buffer
size to 16KB to accomodate the current maximum heap size.
diff --git a/vm/alloc/DdmHeap.c b/vm/alloc/DdmHeap.c
index 78da6cd..f21a875 100644
--- a/vm/alloc/DdmHeap.c
+++ b/vm/alloc/DdmHeap.c
@@ -224,10 +224,18 @@
      * allocation units used by the chunk.
      */
     {
+        size_t needed = (((chunklen/ALLOCATION_UNIT_SIZE + 255) / 256) * 2);
         size_t bytesLeft = ctx->bufLen - (size_t)(ctx->p - ctx->buf);
-        if (bytesLeft < (((chunklen/ALLOCATION_UNIT_SIZE + 255) / 256) * 2)) {
+        if (bytesLeft < needed) {
             flush_hpsg_chunk(ctx);
         }
+
+        bytesLeft = ctx->bufLen - (size_t)(ctx->p - ctx->buf);
+        if (bytesLeft < needed) {
+            LOGW("chunk is too big to transmit (chunklen=%zd, %zd bytes)\n",
+                chunklen, needed);
+            return;
+        }
     }
 
 //TODO: notice when there's a gap and start a new heap, or at least a new range.
@@ -345,7 +353,12 @@
     HPSG_WHAT_DISTINCT_OBJECTS = 1,
 };
 
-#define HPSx_CHUNK_SIZE (4096 - 16)
+/*
+ * Maximum chunk size.  Obtain this from the formula:
+ *
+ * (((maximum_heap_size / ALLOCATION_UNIT_SIZE) + 255) / 256) * 2
+ */
+#define HPSx_CHUNK_SIZE (16384 - 16)
 
 void dlmalloc_walk_heap(void(*)(const void*, size_t, const void*, size_t, void*),void*);