fix: check string for null terminators

This commit is contained in:
Frederick Widjaja
2025-08-07 11:09:44 +07:00
parent 2f83e07a55
commit 5b238c6d0f
+7 -1
View File
@@ -499,7 +499,13 @@ export class EBMLReader {
const { view, offset } = this.reader.getViewAndOffset(this.pos, this.pos + length);
this.pos += length;
return String.fromCharCode(...new Uint8Array(view.buffer, offset, length));
// Actual string length might be shorter due to null terminators
let strLength = 0;
while (strLength < length && view.getUint8(offset + strLength) !== 0) {
strLength += 1;
}
return String.fromCharCode(...new Uint8Array(view.buffer, offset, strLength));
}
readElementId() {