Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How To Make a "Corrupt" File [closed]

Suppose, during testing, you wish to test how the software handles a "corrupt" file.

I have two questions:

1. In general, how do you define a "corrupt" file? In other words, what constitutes a corrupt file?

As an example:

Suppose you need to test a "corrupt" .pdf file.

One suggestion is to simply take a .zip file, change the extension, and test with that. However, I would argue that you are not testing how the program handles a "corrupt .pdf file," but rather, how it handles a .zip file.

Another suggestion is to open the file and insert/delete random bytes. This suggestion is okay, but there are a few problems:

  • It is possible (albeit unlikely) that the sections which are modified or removed are inconsequential. For example, you may simply delete a section of a huge string, which would modify the data, but not necessarily corrupt the file.
  • It is possible that the file can be modified in such a way that the program will refuse to read the file. For example, if the .pdf header is deleted, then maybe the API (or whatever you are using) won't get past that point and the file cannot be tested at all.
  • Similar to the first bullet: If the file is modified dramatically enough, then there is an argument that the resulting file is no longer the same format as the original. So, again, if you were to delete the .pdf header, then maybe that file is no longer a .pdf file. So attempting to test it does not test a corrupt .pdf file, but instead tests some odd variation of a .pdf file.

2. Once a corrupt file is defined, how do you go about creating one?


Here is what I have been thinking so far:

A "corrupt file" is a file that correctly meets the specifications of the file format, but which contains data/bytes that are inherently flawed.

The only example I could think of was if you changed the encoding of the file somehow. You could then possibly apply this method to files of arbitrary format.

Thanks for reading.

like image 782
user807566 Avatar asked May 02 '12 12:05

user807566


People also ask

How do I force a corrupted file to delete?

Sometimes, even though your files get corrupted, unreadable, or damaged, you can delete them by clicking the "Delete" button, holding the "Shift+Delete" buttons, or even dragging them to the recycle bin.

Can corrupt files be recovered?

Corrupted files are computer files that suddenly become inoperable or unusable. There are several reasons why a file may become corrupted. In some cases, it is possible to recover and fix the corrupted file, while at other times it may be necessary to delete the file and replace it with an earlier saved version.


1 Answers

Another suggestion is to open the file and insert/delete random bytes.

This is what I do generally. Whilst I understand the issues that you bullet above, I deem a file to be corrupt if it is unreadable by its native application.

Eg., an xls won't open in Excel, a docx won't open in Word, etc.

like image 96
Ste Avatar answered Sep 23 '22 15:09

Ste