Skip to content

Commit

Permalink
Merge: lab6
Browse files Browse the repository at this point in the history
  • Loading branch information
YingMuo committed Apr 25, 2024
1 parent 6400b30 commit d98826b
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/lab-autograding.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
const files = await github.rest.pulls.listFiles({ owner, repo, pull_number: issue_number });
const changedFiles = files.data.map((file) => file.filename);
const allowedFileRegex = /^lab\d+\/main_test.js$/;
const specialChangedFiles = ["lab5/Answer.md", "lab5/antiasan.c"];
const specialChangedFiles = ["lab5/Answer.md", "lab5/antiasan.c", "lab6/Answer.md"];
if (!changedFiles.every((file) => (allowedFileRegex.test(file) || specialChangedFiles.includes(file)))) {
core.setFailed('The PR contains changes to files other than the allowed files.');
}
Expand Down
2 changes: 2 additions & 0 deletions lab6/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fuzz/
src/bmpcomp
12 changes: 12 additions & 0 deletions lab6/Answer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Name:
ID:

### Fuzz Monitor
```
```

### Run Crash Result
```
```
Binary file added lab6/src/1.bmp
Binary file not shown.
59 changes: 59 additions & 0 deletions lab6/src/hw0302.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
typedef struct _BMPHeader {
char BM[2];
uint32_t size;
uint32_t reserve;
uint32_t offset;
uint32_t header_size;
uint32_t width;
uint32_t height;
uint16_t planes;
uint16_t bpp;
uint32_t compression;
uint32_t bitmap_size;
uint32_t h_res;
uint32_t v_res;
uint32_t palette;
uint32_t important;
}__attribute__((__packed__)) Header;
int main(int argc, char **argv) {
FILE *pF[9];
char *filename = argv[1];
for ( int i=0; i<9; ++i ) {
pF[i] = fopen(filename, "rb");
if ( pF[i] == NULL ) {
printf("error! file %s doesn't exist.\n", filename);
return 0;
}
}
char output[11] = {'o', 'u', 't', 'p', 'u', 't', '.', 'b', 'm', 'p', '\0'};
FILE *pR = fopen(output, "wb");
Header H[9], res;
printf("size of Herder %d\n", sizeof(Header));
for ( int i=0; i<9; ++i ) fread(H+i, sizeof(Header), 1, pF[i]);
res = H[0];
res.height = H[0].height + H[3].height + H[6].height;
res.width = H[0].width + H[1].width + H[2].width;
res.bitmap_size = res.height*res.width*3+(res.width%4*res.height);
res.size = res.bitmap_size + res.offset;
fwrite(&res, sizeof(Header), 1, pR);
for ( int i=2; i<9; i+=3 ) {
for ( int j=0; j<H[i].height; ++j ) {
for ( int k=0; k<3; ++k ) {
uint8_t data[H[i-k].width*3];
fread(data, sizeof(uint8_t), H[i-k].width*3, pF[i-k]);
fwrite(data, sizeof(uint8_t), H[i-k].width*3, pR);
fseek(pF[i-k], H[i-k].width%4, SEEK_CUR);
}
uint8_t padding;
for ( int k=0; k<res.width%4; ++k ) fwrite(&padding, sizeof(uint8_t), 1, pR);
}
}
for ( int i=0; i<9; ++i ) fclose(pF[i]);
fclose(pR);
puts("done!");
return 0;
}
2 changes: 2 additions & 0 deletions lab6/src/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bmpcomp: hw0302.c
$(CC) $< -std=c11 -lm -o $@
15 changes: 15 additions & 0 deletions lab6/validate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

# Check for unwanted files
for file in *; do
if [[ $file != "src" && $file != "src/makefile" && $file != "src/hw0302.c" && $file != "src/1.bmp" && $file != "Answer.md" && $file != "validate.sh" ]]; then
echo "[!] Unwanted file detected: $file."
exit 1
fi
done

echo "[V] Pass"

exit 0

# vim: set fenc=utf8 ff=unix et sw=2 ts=2 sts=2:

0 comments on commit d98826b

Please sign in to comment.