Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
(g_bytevector-base64-encode (make-bytevector 4 65) 1073741824)会让 bin/gf 段错误(SIGSEGV, exit 139),见demo/crash/f03-base64-encode-oob-length.scm。根因:
src/liii_base64.cpp的f_bytevector_base64_encode/f_bytevector_base64_decode的第二参数(长度)直接s7_integer(s7_cadr(args)),与 bytevector 实际长度完全无关;编码循环按声明长度读取in[i],声明 1GB 时越界读取直至撞上未映射内存。负长度还会让负的out_cap进入s7_make_byte_vector。decode 侧越界读通常被Invalid base64 input提前掩盖,但内存越界本身存在。修复
沿用 0142-0145 的模式在 C 入口校验参数,长度增加区间校验:
type-error(length must be an integer)len < 0或len > (bytevector-length bv):value-error(length out of range)复用现有
base64_error报错路径。公开包装bytevector-base64-encode/decode始终传入正确长度,本修复防御的是 C 层入口g_*的直接调用。测试
tests/liii/base64/bytevector-base64-encode-test.scm(6 条)与tests/liii/base64/bytevector-base64-decode-test.scm(6 条):正常编解码 + 长度参数的 type-error/value-error。TDD:修复前 encode 测试文件本身即段错误,修复后 6/6 + 6/6 通过value-error: length out of range(exit 255),验证后按惯例移除并更新 READMEtests/liii/base64-test.scm通过备注
devel/0146.md