duktape: Crash near DUK_UNLIKELY?

I use duktape on android devices, the crash reports reflects a frequently crash at duk_api_stack.c:264:

file: duktape.c
17449 
17450     DUK_ASSERT_CTX_VALID(ctx);
17451     DUK_ASSERT(DUK_INVALID_INDEX < 0);
17452 
17453     vs_size = (duk_idx_t) (thr->valstack_top - thr->valstack_bottom);
17454     DUK_ASSERT(vs_size >= 0);
17455 
17456     if (index < 0) {
17457         index = vs_size + index;
17458         if (DUK_UNLIKELY(index < 0)) { // crash at this line
17459             return NULL;
17460         }
17461     } else {
17462         DUK_ASSERT(index != DUK_INVALID_INDEX);
17463         if (DUK_UNLIKELY(index >= vs_size)) {
17464             return NULL;
17465         }
17466     }
17467 
17468     DUK_ASSERT(index >= 0);

the crash stack:

signal 11 (SIGSEGV)  code 1 (SEGV_MAPERR)  fault addr 0000004c
r0 6f6cf1b8  r1 00000000  r2 400bdbd4  r3 80596fc0
r4 00000000  r5 6ddb5df0  r6 400bdbd4  r7 6f6cf1b8
r8 400bdbd4  r9 00000000  10 00000388  fp 00000067
ip befcc730  sp befcbe00  lr 6dd965b5  pc 6dd961e2  cpsr 400f0030
00  pc 000241e2  my.so
00  pc 000241e2  my.so
01  lr 000245b5  my.so

Can anybody give me some clue on this crash?

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 19 (11 by maintainers)

Most upvoted comments

Hm, 48MB seems a little tight. If you end up doing a lot of allocations and you’re not using a pooled allocator, I could see running out of memory, due to fragmentation if nothing else. Not saying that’s the issue here, but it’s a possibility.

The crash in duk_push_heapptr() looks like you’re mismanaging a heap pointer somewhere and the object it points to has been GC’d. Duktape has no sanity checks for that so if you push a stale heap pointer you will segfault. I would go through the code and double check that all heap pointers are being stashed to keep them reachable.

If so, it should be preceded by an alloc/realloc call returning NULL.