-
-
Notifications
You must be signed in to change notification settings - Fork 109
Harden ASF parser against infinite loop and malformed headers #2624
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,6 @@ import * as AsfObject from './AsfObject.js'; | |
| import { BasicParser } from '../common/BasicParser.js'; | ||
| import { AsfContentParseError } from './AsfObject.js'; | ||
|
|
||
|
|
||
| const debug = initDebug('music-metadata:parser:ASF'); | ||
| const headerType = 'asf'; | ||
|
|
||
|
|
@@ -24,8 +23,10 @@ export class AsfParser extends BasicParser { | |
|
|
||
| public async parse() { | ||
| const header = await this.tokenizer.readToken<AsfObject.IAsfTopLevelObjectHeader>(AsfObject.TopLevelHeaderObjectToken); | ||
| if (!header.objectId.equals(AsfGuid.HeaderObject)) { | ||
| throw new AsfContentParseError(`expected asf header; but was not found; got: ${header.objectId.str}`); | ||
| if (header.numberOfHeaderObjects > 10000) { | ||
| throw new AsfContentParseError( | ||
| `Unrealistic number of ASF header objects: ${header.numberOfHeaderObjects}` | ||
| ); | ||
| } | ||
| await this.parseObjectHeader(header.numberOfHeaderObjects); | ||
|
Comment on lines
24
to
31
|
||
| } | ||
|
Comment on lines
+29
to
32
|
||
|
|
@@ -110,9 +111,6 @@ export class AsfParser extends BasicParser { | |
| // Parse common header of the ASF Object (3.1) | ||
| const header = await this.tokenizer.readToken<AsfObject.IAsfObjectHeader>(AsfObject.HeaderObjectToken); | ||
| const remaining = header.objectSize - AsfObject.HeaderObjectToken.len; | ||
| if (remaining < 0) { | ||
| throw new AsfContentParseError(`Invalid ASF header object size: ${header.objectSize}`); | ||
| } | ||
| // Parse data part of the ASF Object | ||
| switch (header.objectId.str) { | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TopLevelHeaderObjectTokennow reusesHeaderObjectToken.get, but it only enforcesobjectSize >= 24. The ASF top-level Header Object requires at least 30 bytes (GUID+size+numberOfHeaderObjects+reserved). Add a check thatbase.objectSize >= TopLevelHeaderObjectToken.len(30) to properly reject malformed headers in the 24..29 range.