Skip to main content

Assignment overview

In this assignment, you will write a command-line program in C to interact with PNG (Portable Network Graphics) image files. The goal is to familiarize yourself with systems-level C programming through a realistic and challenging project.

Learning objectives

This homework focuses on developing skills in:

File I/O

Reading and writing binary file formats with precise byte-level control

Pointers & Memory

Dynamic memory allocation, pointer manipulation, and memory management

Bitwise Operations

LSB manipulation for steganography and bit-level data processing

Data Structures

Working with complex binary structures and endianness conversions

What you’ll build

You will implement a PNG manipulation tool that can:
1

Parse PNG files

Read and validate PNG file structure, including signature verification and chunk parsing
2

Extract metadata

Parse IHDR (header) and PLTE (palette) chunks to extract image metadata
3

Validate integrity

Implement CRC-32 checksum validation for all PNG chunks
4

Hide messages

Encode secret messages into images using LSB steganography
5

Overlay images

Composite smaller images onto larger ones with palette merging

PNG specification

The official PNG specification is available at: You should familiarize yourself with the specification, particularly:
  • The 8-byte PNG signature
  • Chunk structure (length, type, data, CRC)
  • IHDR chunk format (image header)
  • PLTE chunk format (color palette)
  • IDAT chunks (image data)
  • Big-endian integer encoding

Project structure

The assignment template includes:
PNG_HW/
├── include/          # Header files
│   ├── global.h      # Output macros and constants
│   ├── png_chunks.h  # Chunk parsing functions
│   ├── png_crc.h     # CRC-32 implementation
│   ├── png_reader.h  # PNG file reading
│   ├── png_steg.h    # Steganography functions
│   ├── png_overlay.h # Image overlay functions
│   └── util.h        # Utility functions
├── src/              # Implementation files
│   ├── main.c        # Main program (you fill this in)
│   ├── png_chunks.c
│   ├── png_crc.c
│   ├── png_reader.c
│   ├── png_steg.c
│   ├── png_overlay.c
│   └── util.c
└── tests/            # Criterion test files
    ├── test_chunks.c
    ├── test_crc.c
    ├── test_reader.c
    ├── test_steg.c
    └── test_overlay.c
Some files contain “DO NOT MODIFY” notices at the beginning. These files will be replaced with original versions during grading, so do not modify them.

Allowed libraries

For this assignment: Allowed:
  • glibc (GNU standard C library) including malloc, calloc, fgetc, etc.
  • zlib library for data compression/decompression
  • Sample CRC code from the PNG specification appendix
Disallowed:
  • Binary libraries other than glibc and zlib
  • Existing PNG manipulation libraries
Submitting code that uses disallowed libraries will result in a zero grade and potential academic dishonesty charges.

Academic integrity

You must write your own code. You are not permitted to:
  • Submit source code you did not write yourself
  • Use code from the internet or other students
  • Use AI-generated code without understanding and documenting it
Exceptions:
  • Base code provided in the template repository
  • Code explicitly permitted in writing by the instructor

Timeline and expectations

Due date: Sunday February 15th @ 11:59 PM
This is a challenging project. You should:
  • Start immediately - Do not wait until the last week
  • Allocate regular time - Work on it consistently over several weeks
  • Experiment with data - Use hd (hex dump) to examine PNG files
  • Write your own tests - The provided tests are minimal
  • Test incrementally - Don’t wait to test everything at once
It is extremely unlikely anyone will read the handout and immediately write working code. Plan to spend significant time experimenting and debugging.

Getting help

Resources available to you:
  • README.md - Detailed assignment specification
  • Piazza - Check for updates and clarifications
  • Office hours - Get help from TAs and professor
  • PNG specification - Official documentation
  • Beej’s Guide to C - Excellent C programming reference

Next steps

Requirements

Review detailed assignment requirements

CLI arguments

Start with Part 1: command-line processing

PNG format

Learn about PNG file structure

API reference

Explore the PNG API functions

Build docs developers (and LLMs) love