nBytes 大于 sizeof(payload) 导致读取文件时 payload 数组溢出#86
Open
cllarisy wants to merge 1 commit intokn007:masterfrom
Open
nBytes 大于 sizeof(payload) 导致读取文件时 payload 数组溢出#86cllarisy wants to merge 1 commit intokn007:masterfrom
cllarisy wants to merge 1 commit intokn007:masterfrom
Conversation
|
Thank you for your letter! I've received your letter, I'll reply to you as soon as possible.
|
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.
我在做音频转换时,出现部分不合法的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++, 所以如有建议请和我反馈。
期待回复。