Commit bf70e8d
authored
Determine image file formats by checking file header (#36)
The image format was determined by checking the file extension parsed
from the image path. However, a file's format is defined by its internal
bit layout, not its extension. File extensions are merely human-readable
metadata and do not necessarily reflect the actual contents of a file.
For example, renaming a .jpg file to a different extension does not
change its internal format and could potentially misrepresent the file
as something else, such as a harmful executable.
Relying solely on filenames to determine file formats is unreliable and
may lead to incorrect results. In contrast, file headers contain unique,
format-specific signatures that offer a more accurate and reliable
method for identifying a file's true nature. Therefore, the handler has
been updated to determine the image format by checking the file header,
and the previous reliance on file extensions has been removed.1 parent a6a9970 commit bf70e8d
1 file changed
+37
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
35 | | - | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
36 | 44 | | |
37 | | - | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
38 | 57 | | |
39 | 58 | | |
40 | | - | |
41 | | - | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
42 | 70 | | |
43 | 71 | | |
44 | | - | |
| 72 | + | |
45 | 73 | | |
46 | 74 | | |
47 | 75 | | |
48 | 76 | | |
49 | | - | |
| 77 | + | |
50 | 78 | | |
51 | 79 | | |
52 | 80 | | |
53 | | - | |
54 | 81 | | |
| 82 | + | |
55 | 83 | | |
56 | 84 | | |
57 | 85 | | |
| |||
74 | 102 | | |
75 | 103 | | |
76 | 104 | | |
77 | | - | |
| 105 | + | |
78 | 106 | | |
79 | 107 | | |
80 | 108 | | |
| |||
0 commit comments