mirror of
https://github.com/janet-lang/janet
synced 2025-05-24 10:14:12 +00:00
Address #336 case 6
This commit is contained in:
parent
cc70388846
commit
a3c55681b2
@ -916,7 +916,7 @@ static const uint8_t *unmarshal_one_fiber(
|
|||||||
JanetFiber **out,
|
JanetFiber **out,
|
||||||
int flags) {
|
int flags) {
|
||||||
|
|
||||||
/* Initialize a new fiber */
|
/* Initialize a new fiber with gc friendly defaults */
|
||||||
JanetFiber *fiber = janet_gcalloc(JANET_MEMORY_FIBER, sizeof(JanetFiber));
|
JanetFiber *fiber = janet_gcalloc(JANET_MEMORY_FIBER, sizeof(JanetFiber));
|
||||||
fiber->flags = 0;
|
fiber->flags = 0;
|
||||||
fiber->frame = 0;
|
fiber->frame = 0;
|
||||||
@ -937,16 +937,16 @@ static const uint8_t *unmarshal_one_fiber(
|
|||||||
int32_t stacktop = 0;
|
int32_t stacktop = 0;
|
||||||
|
|
||||||
/* Read ints */
|
/* Read ints */
|
||||||
fiber->flags = readint(st, &data);
|
int32_t fiber_flags = readint(st, &data);
|
||||||
frame = readnat(st, &data);
|
frame = readnat(st, &data);
|
||||||
fiber->stackstart = readnat(st, &data);
|
int32_t fiber_stackstart = readnat(st, &data);
|
||||||
fiber->stacktop = readnat(st, &data);
|
int32_t fiber_stacktop = readnat(st, &data);
|
||||||
fiber->maxstack = readnat(st, &data);
|
int32_t fiber_maxstack = readnat(st, &data);
|
||||||
|
|
||||||
/* Check for bad flags and ints */
|
/* Check for bad flags and ints */
|
||||||
if ((int32_t)(frame + JANET_FRAME_SIZE) > fiber->stackstart ||
|
if ((int32_t)(frame + JANET_FRAME_SIZE) > fiber_stackstart ||
|
||||||
fiber->stackstart > fiber->stacktop ||
|
fiber_stackstart > fiber_stacktop ||
|
||||||
fiber->stacktop > fiber->maxstack) {
|
fiber_stacktop > fiber_maxstack) {
|
||||||
janet_panic("fiber has incorrect stack setup");
|
janet_panic("fiber has incorrect stack setup");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -959,7 +959,7 @@ static const uint8_t *unmarshal_one_fiber(
|
|||||||
|
|
||||||
/* get frames */
|
/* get frames */
|
||||||
stack = frame;
|
stack = frame;
|
||||||
stacktop = fiber->stackstart - JANET_FRAME_SIZE;
|
stacktop = fiber_stackstart - JANET_FRAME_SIZE;
|
||||||
while (stack > 0) {
|
while (stack > 0) {
|
||||||
JanetFunction *func = NULL;
|
JanetFunction *func = NULL;
|
||||||
JanetFuncDef *def = NULL;
|
JanetFuncDef *def = NULL;
|
||||||
@ -1028,25 +1028,31 @@ static const uint8_t *unmarshal_one_fiber(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Check for fiber env */
|
/* Check for fiber env */
|
||||||
if (fiber->flags & JANET_FIBER_FLAG_HASENV) {
|
if (fiber_flags & JANET_FIBER_FLAG_HASENV) {
|
||||||
Janet envv;
|
Janet envv;
|
||||||
fiber->flags &= ~JANET_FIBER_FLAG_HASENV;
|
fiber_flags &= ~JANET_FIBER_FLAG_HASENV;
|
||||||
data = unmarshal_one(st, data, &envv, flags + 1);
|
data = unmarshal_one(st, data, &envv, flags + 1);
|
||||||
janet_asserttype(envv, JANET_TABLE);
|
janet_asserttype(envv, JANET_TABLE);
|
||||||
fiber->env = janet_unwrap_table(envv);
|
fiber->env = janet_unwrap_table(envv);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check for child fiber */
|
/* Check for child fiber */
|
||||||
if (fiber->flags & JANET_FIBER_FLAG_HASCHILD) {
|
if (fiber_flags & JANET_FIBER_FLAG_HASCHILD) {
|
||||||
Janet fiberv;
|
Janet fiberv;
|
||||||
fiber->flags &= ~JANET_FIBER_FLAG_HASCHILD;
|
fiber_flags &= ~JANET_FIBER_FLAG_HASCHILD;
|
||||||
data = unmarshal_one(st, data, &fiberv, flags + 1);
|
data = unmarshal_one(st, data, &fiberv, flags + 1);
|
||||||
janet_asserttype(fiberv, JANET_FIBER);
|
janet_asserttype(fiberv, JANET_FIBER);
|
||||||
fiber->child = janet_unwrap_fiber(fiberv);
|
fiber->child = janet_unwrap_fiber(fiberv);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return data */
|
/* We have valid fiber, finally construct remaining fields. */
|
||||||
fiber->frame = frame;
|
fiber->frame = frame;
|
||||||
|
fiber->flags = fiber_flags;
|
||||||
|
fiber->stackstart = fiber_stackstart;
|
||||||
|
fiber->stacktop = fiber_stacktop;
|
||||||
|
fiber->maxstack = fiber_maxstack;
|
||||||
|
|
||||||
|
/* Return data */
|
||||||
*out = fiber;
|
*out = fiber;
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
@ -216,10 +216,15 @@
|
|||||||
(assert-error "unmarshal errors 4"
|
(assert-error "unmarshal errors 4"
|
||||||
(unmarshal
|
(unmarshal
|
||||||
@"\xD7\xCD\0e/p\x98\0\0\x03\x01\x01\x01\x02\0\0\x04\0\xCEe/p../tools
|
@"\xD7\xCD\0e/p\x98\0\0\x03\x01\x01\x01\x02\0\0\x04\0\xCEe/p../tools
|
||||||
\0\0\0/afl\0\0\x01\0erate\xDE\xDE\xDE\xDE\xDE\xDE\xDE\xDE\xDE\xDE
|
\0\0\0/afl\0\0\x01\0erate\xDE\xDE\xDE\xDE\xDE\xDE\xDE\xDE\xDE\xDE
|
||||||
\xA8\xDE\xDE\xDE\xDE\xDE\xDE\0\0\0\xDE\xDE_unmarshal_testcase3.ja
|
\xA8\xDE\xDE\xDE\xDE\xDE\xDE\0\0\0\xDE\xDE_unmarshal_testcase3.ja
|
||||||
neldb\0\0\0\xD8\x05printG\x01\0\xDE\xDE\xDE'\x03\0marshal_tes/\x02
|
neldb\0\0\0\xD8\x05printG\x01\0\xDE\xDE\xDE'\x03\0marshal_tes/\x02
|
||||||
\0\0\0\0\0*\xFE\x01\04\x02\0\0'\x03\0\r\0\r\0\r\0\r" load-image-dict))
|
\0\0\0\0\0*\xFE\x01\04\x02\0\0'\x03\0\r\0\r\0\r\0\r" load-image-dict))
|
||||||
|
|
||||||
|
# No segfault, valgrind clean.
|
||||||
|
(def x @"\xCC\xCD.nd\x80\0\r\x1C\xCDg!\0\x07\xCC\xCD\r\x1Ce\x10\0\r;\xCDb\x04\xFF9\xFF\x80\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04uu\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\0\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04}\x04\x04\x04\x04\x04\x04\x04\x04#\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\0\x01\0\0\x03\x04\x04\x04\xE2\x03\x04\x04\x04\x04\x04\x04\x04\x04\x04\x14\x1A\x04\x04\x04\x04\x04\x18\x04\x04!\x04\xE2\x03\x04\x04\x04\x04\x04\x04$\x04\x04\x04\x04\x04\x04\x04\x04\x04\x80\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04A\0\0\0\x03\0\0!\xBF\xFF")
|
||||||
|
(unmarshal x load-image-dict)
|
||||||
|
(gccollect)
|
||||||
|
(marshal x make-image-dict)
|
||||||
|
|
||||||
(end-suite)
|
(end-suite)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user