A few quick things out of the way as I know these type of questions often have a malicious background.
- I am not trying to execute something in a file format (jpg)
- I am not trying to simply achieve the end goal (i.e. make something look like a jpg but exectue)
- I'm simply trying to learn the difference between how a computer parses information
So from my understanding a computer dealing with a data file format, such as JPG, PDF, etc etc will only parse the information in what essentially is a container adhering I imagine to specific layouts / specifications. Commonly you hear the difference between a data file format and an executable is that the computer won't "run (execute)" the data file. My question is - how does the computer know what to read, and what to execute? What is the difference? My mental image of a computer is something that reads instructions step by step. If in the middle of a jpg that it was parsing it saw shellcode for popping a message box up, why doesn't it activate when read?
I'm aware that things could be executed via exploits for the software, tricking the parser - perhaps via buffer overflows etc etc. Again, not so much interested in the end goal of how it can be achieved. I'm more interested in how the computer can tell what is meant to be read, what is meant to be executed, and how reading can be achieved without execution.