How can I intentionally corrupt an image file for a project?

Asked 7/1/2017

6 views

2 answers

0

I’m working on a project where I want to deliberately corrupt image files to explore glitch-like effects. I understand that corruption can happen because of bad memory cards, copy errors, failing connectors, or overwritten data, but I’d like to understand what is actually happening at the file level.

Can you intentionally do this by opening an image file in a hex editor and changing bytes manually? More generally, what kinds of file corruption cause visible image glitches versus making the file unreadable altogether?

Originally by Photography Stack Exchange contributor. Source · Licensed CC BY-SA 4.0

Photography Stack Exchange contributor

9y ago

2 Answers

4

Try a web search for "Hex editor". There are several around, including some free ones. They can display the values of the bytes making up the file as (ususally) hexadecimal (base 16) values - each 8 bit byte shows as 2 hexadecimal digits. Some may also allow you to display the values as octal (base 8) or binary (base 2). As with most editors, you can search for things (usually either as normal text, or for byte values) and add/remove/change things.

Typically, what happens when a file is corrupted is that either some part of the file is lost while copying, or extra garbage inserted, or that some of the data values are changed - or some or part of the file is later overwritten by something else.

depending on the image format, changing the data may either change the colour of a pixel (raw pixel values), mess up a line (run length coded values), or make the image unloadable (some header fields or compression schemes).

For most compression schemes, the loading software may be able to tell that there's a problem if the change affects any of the spatial (run length) information, but may not be able to tell if the change only affects colour information - if it's expecting a 1000 pixel long line, and the data decompresses to 1020 or 980, then that's fairly obvious if it's checking, but having a red pixel instead of a green one isn't noticeable. Similarly, if the change trashes essential header information (like the size of the image) then there will be problems.

Depending on what you're trying to do with the corrupted images, you may need to do more research on the image formats involved.

Edit: For anyone who is wondering why the editors show the byte values as hex, octal, or binary values instead of a normal decimal (base 10) number - it's because in a lot of data formats, different parts of the bytes can be used for different things - for example, you might use 2 bits of the 8 bits in a byte to represent 4 possible different colours, and the other 6 to represent a repeat count (0-63, or 1-64 if you add one to the number), and with the hex/octal/binary display it's easier to split the numbers up and work out what the bit pattern is - each digit represents a separate set of bits, unlike decimal, where things get mixed together:

7A (hex - uses digits 0123456789ABCDEF) =

0111 1010 (binary, spaced to show hex relationship - uses digits 0 1) =

01 111 010 (binary, spaced to show octal relationship) =

172 (octal - uses digits 01234567) =

132 decimal, which has no obvious relation to the binary version.

Originally by user61668. Source · Licensed CC BY-SA 4.0

user61668

9y ago

0

AI Answer

Generated from our catalog & community — verify before relying on it.

Yes. A common way to intentionally corrupt an image is to open the file in a hex editor and alter, insert, or delete bytes.

Real corruption usually happens when data is changed, lost, overwritten, truncated during copying, or mixed with garbage data. At the file level, that can affect either:

  • the file structure/header, which may make the image unreadable, or
  • the image data itself, which may produce visible glitches.

What you see depends heavily on the format. Some formats are more tolerant of damage than others; in some cases a changed byte may only alter part of the image, while in others it can break decoding completely.

If your goal is visual corruption rather than total failure, it’s usually better to avoid editing the header and instead experiment with changing small sections of data later in the file. Inserting or deleting bytes can shift everything after that point and often causes stronger corruption than just changing byte values.

So: yes, manual byte editing is a valid approach, and a hex editor is the standard tool for doing it.

UniqueBot

AI

9y ago

Your Answer