Validate mimeType in ImageContentBlock.FromBytes and AudioContentBlock.FromBytes (#1321)

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
This commit is contained in:
Copilot 2026-02-20 03:47:08 +00:00 • committed by GitHub
commit 539481f999
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -425,9 +425,12 @@ public sealed class ImageContentBlock : ContentBlock
/// <remarks>
/// This method stores the provided bytes as <see cref="DecodedData"/> and encodes them to base64 UTF-8 bytes for <see cref="Data"/>.
/// </remarks>
/// <exception cref="InvalidOperationException"></exception>
/// <exception cref="ArgumentNullException"><paramref name="mimeType"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentException"><paramref name="mimeType"/> is empty or composed entirely of whitespace.</exception>
public static ImageContentBlock FromBytes(ReadOnlyMemory<byte> bytes, string mimeType)
{
Throw.IfNullOrWhiteSpace(mimeType);
ReadOnlyMemory<byte> data = EncodingUtilities.EncodeToBase64Utf8(bytes);
return new()
@ -510,9 +513,12 @@ public sealed class AudioContentBlock : ContentBlock
/// <remarks>
/// This method stores the provided bytes as <see cref="DecodedData"/> and encodes them to base64 UTF-8 bytes for <see cref="Data"/>.
/// </remarks>
/// <exception cref="InvalidOperationException"></exception>
/// <exception cref="ArgumentNullException"><paramref name="mimeType"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentException"><paramref name="mimeType"/> is empty or composed entirely of whitespace.</exception>
public static AudioContentBlock FromBytes(ReadOnlyMemory<byte> bytes, string mimeType)
{
Throw.IfNullOrWhiteSpace(mimeType);
ReadOnlyMemory<byte> data = EncodingUtilities.EncodeToBase64Utf8(bytes);
return new()