refactor(media): share the Opus vendor UTF-8 decoder (#17340)

This commit is contained in:
Vincent Koc
2026-12-06 10:30:01 +08:00
committed by GitHub
parent 79a0566aa1
commit 94af21484f
@@ -14,7 +14,7 @@ import type {
VulkanPipelineCacheMetadata,
} from "../../domain/formatMetadata/mediaAssetMetadata.js";
import { BinaryReader } from "../../domain/binaryContainer.js";
import { decodeStrictUtf8 } from "../../domain/strictUtf8.js";
import { decodeUtf8PreservingBomOrNull } from "../../domain/strictUtf8.js";
import type { MediaAssetReaderLimits } from "../../domain/artifactReaderLimits.js";
import { artifactReaderLimitFailure } from "../../resources/index.js";
import { byteToHex } from "../../kernel/byteToHex.js";
@@ -384,17 +384,15 @@ export const oggOpusLayout = async (
limitations.push(
`The OpusTags vendor string declares ${String(vendorLength)} bytes, but only ${String(tagsPrefix.length - 12)} were examined; the vendor was not read.`,
);
else
try {
vendor = decodeStrictUtf8(
tagsPrefix.subarray(12, 12 + vendorLength),
"preserve",
);
} catch {
else {
vendor = decodeUtf8PreservingBomOrNull(
tagsPrefix.subarray(12, 12 + vendorLength),
);
if (vendor === null)
limitations.push(
"The OpusTags vendor string is not valid UTF-8, which RFC 7845 requires; the vendor fact was omitted.",
);
}
}
}
}