Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nBytes 大于 sizeof(payload) 导致读取文件时 payload 数组溢出 #86

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cllarisy
Copy link

我在做音频转换时,出现部分不合法的silk音频文件,处理时读取到后一个 packet 的大小(nBytes)远超过 silk 的最大限制:
counter = fread( &nBytes, sizeof( SKP_int16 ), 1, bitInFile );
因此导致读取的数据长度超过了 payload 的长度定义:
SKP_uint8 payload[ MAX_BYTES_PER_FRAME * MAX_INPUT_FRAMES * ( MAX_LBRR_DELAY + 1 ) ];
counter = fread( payloadEnd, sizeof( SKP_uint8 ), nBytes, bitInFile );
最终导致溢出:
*** stack smashing detected ***: terminated
因此我尝试修复这个问题,将已有对接收数据的合法性检测的代码提前到接收数据阶段:
if (totBytes < 0 || totBytes > sizeof(payload)) { ... }
after:
if( nBytes > MAX_BYTES_PER_FRAME * MAX_INPUT_FRAMES ) { ... }

我的主要方向不是 c/c++, 所以如有建议请和我反馈。
期待回复。

@zhugexiaoshang
Copy link

zhugexiaoshang commented Sep 30, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants