Skip to content

Commit

Permalink
fix(avformat): 对 frame header 做数据检查
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaohappy committed Oct 22, 2024
1 parent 26d4f2a commit 4e5d0f2
Show file tree
Hide file tree
Showing 13 changed files with 20 additions and 16 deletions.
2 changes: 1 addition & 1 deletion dist/avplayer-ui/118.avplayer.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/avplayer-ui/453.avplayer.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/avplayer-ui/avplayer.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/avplayer/118.avplayer.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/avplayer/453.avplayer.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/avplayer/avplayer.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/avtranscoder/118.avtranscoder.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/avtranscoder/411.avtranscoder.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/avtranscoder/453.avtranscoder.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/avtranscoder/888.avtranscoder.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/avtranscoder/952.avtranscoder.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/avtranscoder/avtranscoder.js

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions src/avformat/formats/IFlacFormat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { avMalloc } from 'avutil/util/mem'
import { addAVPacketData } from 'avutil/util/avpacket'
import { IOError } from 'common/io/error'
import { MetaDataBlockType } from './flac/flac'
import { FlacContext } from './flac/type'
import { FlacContext, FrameInfo } from './flac/type'
import { decodeFrameHeader } from './flac/iflac'
import BitReader from 'common/io/BitReader'
import concatTypeArray from 'common/function/concatTypeArray'
Expand Down Expand Up @@ -287,8 +287,7 @@ export default class IFlacFormat extends IFormat {

let i = buffers.length ? 0 : 2

// 根据规范 isVarSize 是不能变的,但发现某些文件中间的某一帧变了,这里将强行指定到第一个帧的值来判断
const sync = this.context.isVarSize < 0 ? [0xf8, 0xf9] : ( this.context.isVarSize ? [0xf9] : [0xf8])
const sync = this.context.isVarSize < 0 ? [0xf8, 0xf9] : (this.context.isVarSize ? [0xf9] : [0xf8])

for (; i < this.context.cacheBuffer.length - 2; i++) {
if (this.context.cacheBuffer[i] === 0xff && array.has(sync, this.context.cacheBuffer[i + 1])) {
Expand Down Expand Up @@ -328,7 +327,12 @@ export default class IFlacFormat extends IFormat {
this.context.bitReader.reset()
this.context.bitReader.appendBuffer(this.context.cacheBuffer.subarray(0, 16))

if (decodeFrameHeader(this.context.bitReader, {}, true) < 0) {
const info: Partial<FrameInfo> = {}
// 检查下一帧的数据是否合法,不合法说明和前面的是同一帧数据
if (decodeFrameHeader(this.context.bitReader, info, true) < 0
|| info.sampleRate !== this.context.frameInfo.sampleRate
|| info.channels !== this.context.frameInfo.channels
) {
buffers.push(this.context.cacheBuffer.subarray(0, 2))
this.context.cachePos += 2n
this.context.cacheBuffer = this.context.cacheBuffer.subarray(2)
Expand Down

0 comments on commit 4e5d0f2

Please sign in to comment.