2

Currently I'm validating a given file by matching its content and extension using the header information. However, .docx and .zip has the same header info (meaning the first 4 bytes are { 80, 75, 3, 4 } for both). Now, if someone just rename a .zip file to .docx file, how am I supposed to prevent it? Is there a way to do it without using some 3rd party utility?

Talha
  • 107
  • 9
  • Just a information, docx is actually a zip file with the extension changed, thats why both have the same header. You can rename a docx to zip, extract the contents and examine the files. – Magnetron Jul 09 '18 at 13:31

1 Answers1

0

I think, you can't preventing a user to rename a file.

In my optinion you can either look inside the zip container and search for characteristic word files and folders like the document.xml or you are using the open xml sdk to be sure to have a valid word file.

https://www.nuget.org/packages/DocumentFormat.OpenXml/

P. Grote
  • 249
  • 1
  • 2
  • 13