@@ -6,7 +6,7 @@ It helps you enforce consistent file upload rules by checking:
66- Allowed file extensions
77- File size limits
88- File signatures (magic numbers) to detect spoofed types
9- - Internal ZIP structure for Office Open XML / OpenDocument formats (` .docx ` , ` .xlsx ` , ` .pptx ` , ` .odt ` )
9+ - Specification conformance for Office Open XML / Open Document Formats (` .docx ` , ` .xlsx ` , ` .pptx ` , ` .odt ` )
1010
1111> ⚠️ ** Important:** This library should be part of a ** defense-in-depth** strategy.
1212 It does not replace antivirus scanning, sandboxing, or other security controls.
@@ -16,7 +16,7 @@ It does not replace antivirus scanning, sandboxing, or other security controls.
1616- ✅ Validate files by ** extension**
1717- ✅ Validate files by ** size**
1818- ✅ Validate files by ** signature (_ magic-numbers_ )**
19- - ✅ Validate files by ** internal ZIP structure ** for archive-based formats (_ Open XML and OpenDocument formats _ )
19+ - ✅ Validate files by ** specification conformance ** for archive-based formats (_ Open XML and Open Document Formats _ )
2020- ✅ Validate using file path, ` Stream ` , or ` byte[] `
2121- ✅ Configure which file types to support
2222- ✅ Configure whether to ** throw exceptions** or simply return a boolean
@@ -51,7 +51,7 @@ var isValid = fileValidator.IsValidFile("example.pdf", fileStream);
5151### Using the fluent builder
5252
5353``` csharp
54- var configuration = new FileValidatorConfigurationBuilder ()
54+ var configuration = new FileValidatorConfigurationBuilder ()
5555 .AllowFileTypes (FileExtensions .Pdf , FileExtensions .Jpg , FileExtensions .Png )
5656 .SetFileSizeLimit (ByteSize .MegaBytes (25 ))
5757 .SetThrowExceptionOnInvalidFile (false )
@@ -71,13 +71,14 @@ The `FileValidator` class provides methods to validate specific aspects of a fil
7171> 1 . Extension validation
7272> 2 . File size validation
7373> 3 . Signature (magic-number) validation
74- > 4 . Optional Open XML / OpenDocument structure validation (for supported types)
74+ > 4 . Optional Open XML / Open Document Format specification conformance validation (for supported types)
7575
7676``` csharp
7777bool isExtensionValid = fileValidator .IsValidFileType (fileName );
7878bool isFileSizeValid = fileValidator .HasValidSize (fileStream );
7979bool isSignatureValid = fileValidator .HasValidSignature (fileName , fileStream );
8080bool isOpenXmlValid = fileValidator .IsValidOpenXmlDocument (fileName , fileStream );
81+ bool isOpenDocumentFormatValid = fileValidator .IsValidOpenDocumentFormat (fileName , fileStream );
8182```
8283
8384### Example
@@ -137,11 +138,11 @@ The following file extensions are supported by the `FileValidator`:
137138
138139For some formats, additional checks are performed:
139140
140- - ** Office Open XML / OpenDocument ** (` .docx ` , ` .xlsx ` , ` .pptx ` , ` .odt ` ):
141+ - ** Office Open XML / Open Document Format ** (` .docx ` , ` .xlsx ` , ` .pptx ` , ` .odt ` ):
141142 - Extension
142143 - File size
143144 - Signature
144- - Internal ZIP structure (basic format sanity)
145+ - Specification conformance
145146
146147- ** Other binary formats** (e.g. images, audio, video such as ` .jpg ` , ` .png ` , ` .mp3 ` , ` .mp4 ` ):
147148 - Extension
@@ -164,10 +165,12 @@ When `ThrowExceptionOnInvalidFile` is set to `true`, validation functions will t
164165
165166| Exception type | Scenario |
166167| --| --|
168+ | ` EmptyFileException ` | Thrown when the file content is ` null ` or empty, indicating a file without any content. |
167169| ` UnsupportedFileException ` | Thrown when the file extension is not in the list of supported types. |
168170| ` InvalidFileSizeException ` | Thrown when the file size exceeds the configured file size limit. |
169171| ` InvalidSignatureException ` | Thrown when the file's signature does not match the expected signature for its type. |
170172| ` InvalidOpenXmlFormatException ` | Thrown when the internal structure of an Open XML file is invalid (` .docx ` , ` .xlsx ` , ` .pptx ` , etc.). |
173+ | ` InvalidOpenDocumentFormatException ` | Thrown when the specification conformance of an Open Document Format file is invalid (` .odt ` , etc.). |
171174
172175## When to use this package
173176
@@ -176,4 +179,4 @@ When `ThrowExceptionOnInvalidFile` is set to `true`, validation functions will t
176179- ✅ When you want ** defense-in-depth** against spoofed or malicious files
177180
178181## License
179- _ ByteGuard FileValidator is copyright © ByteGuard Contributors - Provided under the MIT license._
182+ _ ByteGuard FileValidator is Copyright © ByteGuard Contributors - Provided under the MIT license._
0 commit comments