Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

JS_ThrowStackOverflow may overflow stack itself

未关闭
#893 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
c
领域
backend

调研方向

Read build_backtrace() in quickjs.c around the stack-heavy JSCallSiteData allocation and the char buf[256] local mentioned in the issue. Trace how JS_ThrowStackOverflow() reaches backtrace construction, then assess the proposed approaches and their stack requirements. Done means throwing at the configured stack limit cannot itself overflow the physical stack.

由索引模型根据 Issue 内容生成。

描述

Hello,

QuickJS supports stack limiting with JS_SetMaxStackSize(), and many operations check remaining stack size before alloca() or calling functions. These checks call JS_ThrowStackOverflow(), which should throw corresponding exception. Obviously this exception has a stacktrace.
But the problem is that build_backtrace() function consumes huge amount of stack itself. For example, just this line implies x64 JSCallSiteData structs, each of them is x3 JSValue (+ 9 bytes + align), and each JSValue may be up to 16 bytes on x64 machine (depending on flags). This gives us 64 * aligned(3 * 16 + 9) = 3840 bytes. The full call chain performed to fill backtrace also includes other stack-heavy things, like char buf[256]. Since the exception itself was thrown because we've already reached stack limit, there is a risk of "physically" overflowing the stack if the limit was configured somewhat near the real stack size.

For now the only workaround is to set limit way lower than real stack size, but the needed spare space seems to be unpredictable.
Proposed solutions:

  1. Calculate and enforce maximum stack consumption for JS_ThrowStackOverflow() and specify it in documentation;
  2. Make build_backtrace() and other corresponding functions less stack-heavy, moving every possible local value on (pre-allocated?) heap buffer;
  3. Add some stack checks to throwing-related functions and fallback to skipping backtrace if building stacktrace is impossible.
主要语言
C
星标
3.9k
派生
389
平均合并
4 天 1 小时
30 天内合并 PR
24

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

quickjs-ng/quickjs 的其他 Issue

查看 quickjs-ng/quickjs 的全部 Issue

相似的 Issue

更多 C Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。