This is an archived copy of a previous semester's site.
Please see the current semester's site.
Your second C program explores the implementation and use of a widely-used technical specification. You will implement a small part of the PNG technical specification and use your implementation to hide a GIF within a PNG file.
| 340.png | natalia.png | luther.png |
|---|---|---|
![]() |
![]() |
![]() |
In your CS 340 directory, merge the initial starting files with the following commands:
git fetch release
git merge release/mp2 --allow-unrelated-histories -m "Merging initial files"The World Wide Web Consortium (W3C) is an international community where [many] work together to develop Web standards
1 Quoted from https://www.w3.org/about/. One of the web standards that the W3C published and maintains is the Portable Network Graphics (PNG) Specification (Second Edition)
. This specification fully and completely defines how PNG image files work.
To complete Part 1 of this MP, you must complete a small PNG library that reads the PNG signature
and chunks
found in PNG files:
PNG signatureand
chunks.
htons, ntohs, htonl, ntohl helpful for converting values between host and network byte order.lib/png.c (and the struct in lib/png.h) to complete Part 1.lib/crc.{c,h} that defines crc32(const void *data, size_t n_bytes, uint32_t* crc). This function takes in a pointer to data of n_bytes and writes the 32-bit CRC value into the address provided by crc. It also lets you break the data into chunks, passing in the first chunk, then the second, and then checking the result.
The design on the PNG library is a file-stream based library where you need only to return the next chunk in the file. Therefore, it is highly recommended you only read the data necessary to complete the function and read the next part of the file the next time a library function is called.
PNG_open requires only that you verify the PNG signature. It is recommended you do not read any additional data beyond the signature.
PNG_read requires you to return data about the next PNG chunk. It is recommended you only read the data for one chunk when this function is called.You will need to open a file for reading or writing in C. The following C library calls may be helpful:
fopen to open a new file. Use "r" or "r+" as the second parameter to open the file for reading and "w" as the second parameter to open the file for writing.fread to read from an open file.fwrite to write to an open file.fclose to close an open file. Note that if you write but never close it is up to the OS whether the data makes it to the file or not.make test to compile the test suite../test "[part=1]" to run the tests that have been tagged with [part=1] (covering this portion of the MP).In this MP, we have provided two programs that are already complete:
png-analyze.c.png-rewrite.c.The png-analyze.c and png-rewrite.c files use your library from Part 1. If your library is not complete, these programs will not run correctly! Here are several example runs of the programs that you should run to explore what the provided code does for you:
make to compile,./png-analyze 340.png to view the chunks in 340.png./png-analyze sample/natalia.png to view the chunks in sample/natalia.png./png-analyze sample/luther.png to view the chunks in sample/luther.pngsample/natalia.png and sample/luther.png both have a uiuc chunk – this is our hidden GIF file! You will need to extract it from the PNG file.Complete png-hideGIF.c to hide a GIF file within a uiuc chunk in a provided PNG file. The first command line argument (argv[1]) is the normal PNG file that needs to be modified to hide an GIF image and the second argument (argv[2]) is the GIF to be hidden.
Your png-hideGIF.c file will be very similar to the provided png-rewrite.c program except that you need to add an additional PNGChunk somewhere between IHDR and IEND (it cannot be before the IHDR chunk or after the IEND chunk, but it otherwise can be anywhere in between the two chunks).
Once complete, make sure to test your program:
png-analyze to make sure the hidden uiuc chunk is present,png-extractGIF program to ensure you can extract the GIF you hide in the file,As a final check, run ./test to ensure you pass all test cases.
For full credit, your MP must run valgrind clean
.
On Windows/WSL, you can directly run valgrind with valgrind ./test.
On macOS, you can run valgrind via a docker container:
Only once, you need to build your docker container using: docker build -t cs340 .
Then, you can run valgrind with the following commands:
docker run --rm -it -v "`pwd`":/mp2 cs340 "make clean"
docker run --rm -it -v "`pwd`":/mp2 cs340 "make test"
docker run --rm -it -v "`pwd`":/mp2 cs340 "valgrind --leak-check=full --show-leak-kinds=all ./test"In your solution, you must only modify the following files. Modifications of other files may break things:
png-extractGIF.cpng-hideGIF.clib/png.clib/png.hThis MP also has an extra credit addition, MP2++, with the same due date as the main MP
Once you have locally passed all the tests, you will need to submit and grade your code. First commit using the standard git commands:
git add -A
git commit -m "MP submission"
git pushThe initial grading is done via a manual GitHub Action. You MUST complete this step before the deadline to earn any points for the MP:
ActionTab
mp2 autograding
Run Workflowbutton (located on the blue bar)
Run Workflow
2/3 of the points are for passing the automated tests; 1/3 are for valgrind finding no errors.