Skip to content

Commit 25bf7ae

Browse files
committed
feat: lab6
1 parent 34da9a4 commit 25bf7ae

File tree

7 files changed

+91
-1
lines changed

7 files changed

+91
-1
lines changed

Diff for: .github/workflows/lab-autograding.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
const files = await github.rest.pulls.listFiles({ owner, repo, pull_number: issue_number });
4646
const changedFiles = files.data.map((file) => file.filename);
4747
const allowedFileRegex = /^lab\d+\/main_test.js$/;
48-
const specialChangedFiles = ["lab5/Answer.md", "lab5/antiasan.c"];
48+
const specialChangedFiles = ["lab5/Answer.md", "lab5/antiasan.c", "lab6/Answer.md"];
4949
if (!changedFiles.every((file) => (allowedFileRegex.test(file) || specialChangedFiles.includes(file)))) {
5050
core.setFailed('The PR contains changes to files other than the allowed files.');
5151
}

Diff for: lab6/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
fuzz/
2+
src/bmpcomp

Diff for: lab6/Answer.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Name:
2+
ID:
3+
4+
### Fuzz Monitor
5+
```
6+
7+
```
8+
9+
### Run Crash Result
10+
```
11+
12+
```

Diff for: lab6/src/1.bmp

987 KB
Binary file not shown.

Diff for: lab6/src/hw0302.c

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#include <stdio.h>
2+
#include <stdint.h>
3+
#include <stdlib.h>
4+
#include <string.h>
5+
typedef struct _BMPHeader {
6+
char BM[2];
7+
uint32_t size;
8+
uint32_t reserve;
9+
uint32_t offset;
10+
uint32_t header_size;
11+
uint32_t width;
12+
uint32_t height;
13+
uint16_t planes;
14+
uint16_t bpp;
15+
uint32_t compression;
16+
uint32_t bitmap_size;
17+
uint32_t h_res;
18+
uint32_t v_res;
19+
uint32_t palette;
20+
uint32_t important;
21+
}__attribute__((__packed__)) Header;
22+
int main(int argc, char **argv) {
23+
FILE *pF[9];
24+
char *filename = argv[1];
25+
for ( int i=0; i<9; ++i ) {
26+
pF[i] = fopen(filename, "rb");
27+
if ( pF[i] == NULL ) {
28+
printf("error! file %s doesn't exist.\n", filename);
29+
return 0;
30+
}
31+
}
32+
char output[11] = {'o', 'u', 't', 'p', 'u', 't', '.', 'b', 'm', 'p', '\0'};
33+
FILE *pR = fopen(output, "wb");
34+
Header H[9], res;
35+
printf("size of Herder %d\n", sizeof(Header));
36+
for ( int i=0; i<9; ++i ) fread(H+i, sizeof(Header), 1, pF[i]);
37+
res = H[0];
38+
res.height = H[0].height + H[3].height + H[6].height;
39+
res.width = H[0].width + H[1].width + H[2].width;
40+
res.bitmap_size = res.height*res.width*3+(res.width%4*res.height);
41+
res.size = res.bitmap_size + res.offset;
42+
fwrite(&res, sizeof(Header), 1, pR);
43+
for ( int i=2; i<9; i+=3 ) {
44+
for ( int j=0; j<H[i].height; ++j ) {
45+
for ( int k=0; k<3; ++k ) {
46+
uint8_t data[H[i-k].width*3];
47+
fread(data, sizeof(uint8_t), H[i-k].width*3, pF[i-k]);
48+
fwrite(data, sizeof(uint8_t), H[i-k].width*3, pR);
49+
fseek(pF[i-k], H[i-k].width%4, SEEK_CUR);
50+
}
51+
uint8_t padding;
52+
for ( int k=0; k<res.width%4; ++k ) fwrite(&padding, sizeof(uint8_t), 1, pR);
53+
}
54+
}
55+
for ( int i=0; i<9; ++i ) fclose(pF[i]);
56+
fclose(pR);
57+
puts("done!");
58+
return 0;
59+
}

Diff for: lab6/src/makefile

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bmpcomp: hw0302.c
2+
$(CC) $< -std=c11 -lm -o $@

Diff for: lab6/validate.sh

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
# Check for unwanted files
4+
for file in *; do
5+
if [[ $file != "src" && $file != "src/makefile" && $file != "src/hw0302.c" && $file != "src/1.bmp" && $file != "Answer.md" && $file != "validate.sh" ]]; then
6+
echo "[!] Unwanted file detected: $file."
7+
exit 1
8+
fi
9+
done
10+
11+
echo "[V] Pass"
12+
13+
exit 0
14+
15+
# vim: set fenc=utf8 ff=unix et sw=2 ts=2 sts=2:

0 commit comments

Comments
 (0)