Skip to content

Commit

Permalink
Update file validators to handle mp3 and rtf formats (#123)
Browse files Browse the repository at this point in the history
Handle case where very small files causes an exception to be thrown on validation
  • Loading branch information
JRD-OneBeyond authored Nov 8, 2023
1 parent e75b895 commit 27f8725
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ public virtual void ValidateFileContent(string fileName, string contentType, byt
ValidateFileContent(
fileName,
contentType,
(sizeToRead) => new ReadOnlySpan<byte>(content, 0, sizeToRead).ToArray());
(sizeToRead) => new ReadOnlySpan<byte>(content, 0, sizeToRead > content.Length
? content.Length
: sizeToRead
).ToArray());
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ public FileValidatorBuilder AllowVideo()
.AddValidator(new MpegValidator());

public FileValidatorBuilder AllowAudio()
=> AddValidator(new WavValidator());
=> AddValidator(new WavValidator())
.AddValidator(new Mp3Validator());

public FileValidatorBuilder AllowVisio()
=> AddValidator(new VisioValidator());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ public sealed class WordValidator : FileSignatureValidator
public WordValidator()
: base(
"application/msword",
new[] { ".doc" },
"D0-CF-11-E0-A1-B1-1A-E1")
new[] { ".doc", ".rtf" },
new[] {
"D0-CF-11-E0-A1-B1-1A-E1",
// rtf will have different signatures depending on which program created them
"50-4B-03-04-14",
"7B-5C-72-74-66"
})
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace OneBeyond.Studio.Crosscuts.Utilities.FileUploadValidators.OtherValidators;

public sealed class Mp3Validator : FileSignatureValidator
{
public Mp3Validator()
: base(
"audio/mpeg",
new[] { ".mp3" },
new[]
{
"FF-FB",
"49-44-33",
"FF-F2"
})
{
}
}

0 comments on commit 27f8725

Please sign in to comment.