File Names and Extensions

Every file stored on a computer has a file name. These files also often have file extensions. File extensions allow the computer’s operations system to know what application software should be used to open the file, since not all applications can open all file types. The extensions can also help the user remember the type of data stored in the file. For instance, .docx files open with word processors like Microsoft Word, while .jpg files are typically opened with image viewers.

Extensions are typically added by the computer when the file is created, but they can also be typed as part of the file name by the user. For example, a file named funny.jpg might not actually be a JPEG image, which can confuse the user.

Warning: Always ensure that the extension matches the file type you are working with. An incorrect extension can prevent the file from opening properly. In certain classes, the instructors may specify a file type and naming convention. If you don’t turn in the correct file name, it may not get graded properly!

Some computers (primarily computers running Windows) may not always display the file extension.  To know what extension a file should have, you can right-click on that file in your file explorer and choose “properties.” This will give you information about the file such as its size and what file type it is.

File Manipulation

A file is nothing more than a sequence of bytes (explained in more detail in the Hardware chapter). The interpretation of those bytes is what produces, or doesn’t produce, the desired result, such as a Word document or JPEG image.

Consider the following image1.

If you save the png image file and open it using NotePad (Windows), Text Edit (OS X), or Nano (Linux) you would notice that the file opens without generating an error. It might look very weird! Here’s a portion of what it looks like on TextEdit.

âPNG

IHDR	:2XWUFPLTEˇˇˇÉR“®QÊ≥?[:S6fi¥\ÇxdËΩ^fl¨B»¢Lˆ‚¥^N4èZ‚∫d^>,tN"÷ÆX¢zdä~d9& G/Ҕκ◊¨	¿Öœî΃≠x
·¥
Ò‘*∂~
—õ	‚º«ätSóa§mÏ¥ÎÕ(¨	¡ã
•r
Ûƒ≥y◊ñıΩ¥ìöwfl•	Ÿ≥õfıÕ1πÉ	ÌÃÚ∂

The problem with opening the file in one of those programs is that the information in the file is not presented in a way that the user can understand– it is still a representation of the bytes that compose the file. Image viewing/editing software, such as Photoshop or MS Paint, is designed to interpret those bytes and create an image that your eyes and brain can process.

Since it’s just text, you can change the text by typing into your text editor directly and then opening up the changed file. The file was manipulated, the bytes were changed, and the graphics software simply translated the new information into the image. Here’s a changed Tux2.

Here’s the top of the text for the png image. It is different, and the computer is interpreting it as an image. For most humans, this is not readable. But the two images are visually related and many humans can interpret the visual data.

âPNG

IHDR	:ÜßgsRGBÆŒÈYiTXtXML:com.adobe.xmp<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="XMP Core 5.4.0">
   <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
      <rdf:Description rdf:about=""
            xmlns:tiff="http://ns.adobe.com/tiff/1.0/">
         <tiff:Orientation>1</tiff:Orientation>
      </rdf:Description>
   </rdf:RDF>
</x:xmpmeta>
L¬'Y@IDATxÏΩy\œk˜ˇ{ôEÑ$JQ2dHd,Iî!3°KIDÜîÃÛP “hñ!CÉπT"cTÊD%Q2&ûÁsŒπù«Ô{~ü˚~l?ªˆvÔ˜ü˚èkÍ£k]ØıZk=ó∏ú”Ö>>±|\[å≥a;¥C{ır]˙¯˚q-≈ŒÜ¥”•«◊À‰tÈÉOÏG÷;cÿNõ–_ëŒKflüÙ˜Ûfl}ѧ(=“¯üÄêѧ†$))ˡîAàˇA§")ÄHD¸ß"…Éë<(…Éí	)ô∞í	-ôˇ©!§*ÜT≈ë™XRÔ?U1≈ä Rëà@§"˛Së»iH√IÃ,¿2◊¡ú∏<ˇ˚∫o7éïÃQUK«’ è^ÅXº.ê˙`§>"Ñ‘Û_÷ì\´∫ÓÑ

Malicious Use

Example:

A virus is created and saved to the file funnypic.exe. For the computer to run the virus program, it must think that the virus is an executable (.exe) file type. If you open the program, the virus infects your computer.

As mentioned before, some operating systems hide file extensions by default in order to save screen space and make the file icons shorter and easier to read. In the above example, the file would most likely appear as funnypic on the user’s screen. This means that users could double-click an icon that installs a virus. One defense against this lies in the icon image. Particular icons are associated with certain file types, such as the recognizable manila folder icon.  If there is a file called funnypic.jpg, but the icon displayed is not an image icon, the user should double check the file-type and perform a virus scan.

Virus protection software with real-time scanning will help prevent unwanted .exe files.

  1. “Tux” (Larry Ewing lewing@isc.tamu.edu, The GIMP software) (rights) ↩︎
  2. ECB Penguin, Robert David Graham. ↩︎