Skip to content

Commit 02f20a6

Browse files
committed
refactor: pass max buffer to binarystylesheet
1 parent bbc7f5b commit 02f20a6

7 files changed

Lines changed: 22 additions & 22 deletions

File tree

packages/alphatab/src/generated/CoreSettingsJson.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,4 @@ export interface CoreSettingsJson {
174174
* ```
175175
*/
176176
includeNoteBounds?: boolean;
177-
/**
178-
* This setting controls the escape hatch for handling potentially malicous or corrupt
179-
* input files. At selected spots in the codebase, we use this buffer size as maximum
180-
* allowed sizes. e.g. during unzipping or decoding strings.
181-
* This prevents resource exhaustion, especially when alphaTab is used on server side.
182-
* Increase this buffer size if you need to handle very big files.
183-
* @defaultValue `128000000`
184-
* @category Core
185-
* @since 1.9.0
186-
*/
187-
maxDecodingBufferSize?: number;
188177
}

packages/alphatab/src/generated/CoreSettingsSerializer.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ export class CoreSettingsSerializer {
4545
o.set("loglevel", obj.logLevel as number);
4646
o.set("useworkers", obj.useWorkers);
4747
o.set("includenotebounds", obj.includeNoteBounds);
48-
o.set("maxdecodingbuffersize", obj.maxDecodingBufferSize);
4948
return o;
5049
}
5150
public static setProperty(obj: CoreSettings, property: string, v: unknown): boolean {
@@ -92,9 +91,6 @@ export class CoreSettingsSerializer {
9291
case "includenotebounds":
9392
obj.includeNoteBounds = v! as boolean;
9493
return true;
95-
case "maxdecodingbuffersize":
96-
obj.maxDecodingBufferSize = v! as number;
97-
return true;
9894
}
9995
return false;
10096
}

packages/alphatab/src/generated/ImporterSettingsJson.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,15 @@ export interface ImporterSettingsJson {
6767
* ![Disabled](https://alphatab.net/img/reference/property/beattextaslyrics-disabled.png)
6868
*/
6969
beatTextAsLyrics?: boolean;
70+
/**
71+
* This setting controls the escape hatch for handling potentially malicous or corrupt
72+
* input files. At selected spots in the codebase, we use this buffer size as maximum
73+
* allowed sizes. e.g. during unzipping or decoding strings.
74+
* This prevents resource exhaustion, especially when alphaTab is used on server side.
75+
* Increase this buffer size if you need to handle very big files.
76+
* @defaultValue `128000000`
77+
* @category Core
78+
* @since 1.9.0
79+
*/
80+
maxDecodingBufferSize?: number;
7081
}

packages/alphatab/src/generated/ImporterSettingsSerializer.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export class ImporterSettingsSerializer {
2323
o.set("encoding", obj.encoding);
2424
o.set("mergepartgroupsinmusicxml", obj.mergePartGroupsInMusicXml);
2525
o.set("beattextaslyrics", obj.beatTextAsLyrics);
26+
o.set("maxdecodingbuffersize", obj.maxDecodingBufferSize);
2627
return o;
2728
}
2829
public static setProperty(obj: ImporterSettings, property: string, v: unknown): boolean {
@@ -36,6 +37,9 @@ export class ImporterSettingsSerializer {
3637
case "beattextaslyrics":
3738
obj.beatTextAsLyrics = v! as boolean;
3839
return true;
40+
case "maxdecodingbuffersize":
41+
obj.maxDecodingBufferSize = v! as number;
42+
return true;
3943
}
4044
return false;
4145
}

packages/alphatab/src/importer/BinaryStylesheet.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,18 @@ export class BinaryStylesheet {
7676
private readonly _types: Map<string, DataType> = new Map();
7777
public readonly raw: Map<string, unknown> = new Map();
7878

79-
public constructor(data?: Uint8Array) {
79+
public constructor(data?: Uint8Array, maxDecodingBufferSize: number = 0) {
8080
if (data) {
81-
this._read(data);
81+
this._read(data, maxDecodingBufferSize);
8282
}
8383
}
8484

85-
private _read(data: Uint8Array) {
85+
private _read(data: Uint8Array, maxDecodingBufferSize: number) {
8686
// BinaryStylesheet apears to be big-endien
8787
const readable: ByteBuffer = ByteBuffer.fromBuffer(data);
8888
const entryCount: number = IOHelper.readInt32BE(readable);
8989
for (let i: number = 0; i < entryCount; i++) {
90-
const key: string = GpBinaryHelpers.gpReadString(readable, readable.readByte(), 'utf-8');
90+
const key: string = GpBinaryHelpers.gpReadString(readable, readable.readByte(), 'utf-8', maxDecodingBufferSize);
9191
const type: DataType = readable.readByte() as DataType;
9292
this._types.set(key, type);
9393
switch (type) {
@@ -104,7 +104,7 @@ export class BinaryStylesheet {
104104
this.addValue(key, fvalue);
105105
break;
106106
case DataType.String:
107-
const s: string = GpBinaryHelpers.gpReadString(readable, IOHelper.readInt16BE(readable), 'utf-8');
107+
const s: string = GpBinaryHelpers.gpReadString(readable, IOHelper.readInt16BE(readable), 'utf-8', maxDecodingBufferSize);
108108
this.addValue(key, s);
109109
break;
110110
case DataType.Point:

packages/alphatab/src/importer/Gp7To8Importer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export class Gp7To8Importer extends ScoreImporter {
7878

7979
if (binaryStylesheetData) {
8080
Logger.debug(this.name, 'Start Parsing BinaryStylesheet');
81-
const stylesheet: BinaryStylesheet = new BinaryStylesheet(binaryStylesheetData);
81+
const stylesheet: BinaryStylesheet = new BinaryStylesheet(binaryStylesheetData, this.settings.importer.maxDecodingBufferSize);
8282
stylesheet.apply(score);
8383
Logger.debug(this.name, 'BinaryStylesheet parsed');
8484
}

packages/alphatab/src/importer/GpxImporter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export class GpxImporter extends ScoreImporter {
6969

7070
if (binaryStylesheetData) {
7171
Logger.debug(this.name, 'Start Parsing BinaryStylesheet');
72-
const binaryStylesheet: BinaryStylesheet = new BinaryStylesheet(binaryStylesheetData);
72+
const binaryStylesheet: BinaryStylesheet = new BinaryStylesheet(binaryStylesheetData, this.settings.importer.maxDecodingBufferSize);
7373
binaryStylesheet.apply(score);
7474
Logger.debug(this.name, 'BinaryStylesheet parsed');
7575
}

0 commit comments

Comments
 (0)