From 6d447660c226667f7ecaf80cc8d51c81ea669059 Mon Sep 17 00:00:00 2001 From: Vanilagy <1696106+Vanilagy@users.noreply.github.com> Date: Mon, 11 Aug 2025 16:10:43 +0200 Subject: [PATCH] Clarify EBML strings are ASCII --- src/input-format.ts | 2 +- src/matroska/ebml.ts | 7 +++---- src/matroska/matroska-demuxer.ts | 6 +++--- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/input-format.ts b/src/input-format.ts index 4c4c1c5..142ee0d 100644 --- a/src/input-format.ts +++ b/src/input-format.ts @@ -154,7 +154,7 @@ export class MatroskaInputFormat extends InputFormat { } }; break; case EBMLId.DocType: { - const docType = ebmlReader.readString(size); + const docType = ebmlReader.readAsciiString(size); if (docType !== desiredDocType) { return false; } diff --git a/src/matroska/ebml.ts b/src/matroska/ebml.ts index ace8b18..ab5d8d4 100644 --- a/src/matroska/ebml.ts +++ b/src/matroska/ebml.ts @@ -312,8 +312,7 @@ export class EBMLWriter { this.writer.write(this.helper.subarray(0, pos)); } - // Assumes the string is ASCII - writeString(str: string) { + writeAsciiString(str: string) { this.writer.write(new Uint8Array(str.split('').map(x => x.charCodeAt(0)))); } @@ -359,7 +358,7 @@ export class EBMLWriter { this.writeUnsignedInt(data.data, size); } else if (typeof data.data === 'string') { this.writeVarInt(data.data.length); - this.writeString(data.data); + this.writeAsciiString(data.data); } else if (data.data instanceof Uint8Array) { this.writeVarInt(data.data.byteLength, data.size); this.writer.write(data.data); @@ -495,7 +494,7 @@ export class EBMLReader { return value; } - readString(length: number) { + readAsciiString(length: number) { const { view, offset } = this.reader.getViewAndOffset(this.pos, this.pos + length); this.pos += length; diff --git a/src/matroska/matroska-demuxer.ts b/src/matroska/matroska-demuxer.ts index adafd0b..641f3e6 100644 --- a/src/matroska/matroska-demuxer.ts +++ b/src/matroska/matroska-demuxer.ts @@ -731,7 +731,7 @@ export class MatroskaDemuxer extends Demuxer { switch (id) { case EBMLId.DocType: { - this.isWebM = reader.readString(size) === 'webm'; + this.isWebM = reader.readAsciiString(size) === 'webm'; }; break; case EBMLId.Seek: { @@ -940,7 +940,7 @@ export class MatroskaDemuxer extends Demuxer { case EBMLId.CodecID: { if (!this.currentTrack) break; - this.currentTrack.codecId = reader.readString(size); + this.currentTrack.codecId = reader.readAsciiString(size); }; break; case EBMLId.CodecPrivate: { @@ -959,7 +959,7 @@ export class MatroskaDemuxer extends Demuxer { case EBMLId.Language: { if (!this.currentTrack) break; - this.currentTrack.languageCode = reader.readString(size); + this.currentTrack.languageCode = reader.readAsciiString(size); if (!isIso639Dash2LanguageCode(this.currentTrack.languageCode)) { this.currentTrack.languageCode = UNDETERMINED_LANGUAGE;