[hackers] [farbfeld] Remove dimension checks || FRIGN
commit 96faf20b1bcef354e6b1fd03a26c286070c52e74
Author: FRIGN <dev_AT_frign.de>
AuthorDate: Sun Apr 10 22:54:42 2016 +0200
Commit: FRIGN <dev_AT_frign.de>
CommitDate: Sun Apr 10 22:54:42 2016 +0200
Remove dimension checks
This may come as a surprise, but I'd like the libraries to handle
these cases.
Maybe some day libpng supports 0x0 images, so why impose artificial
limits here?
Same with ppm.
For me, an ideal data converter loses as little information as possible.
In mixed cases (dimensions 0xn, where n > 0) we could print a warning,
but here, 2 principles come at play:
- GIGO (garbage in, garbage out)
- no information loss if possible
Given the code later on won't try to access the malloc(0) region, we
are also all safe.
diff --git a/ff2jpg.c b/ff2jpg.c
index d489774..3da35e2 100644
--- a/ff2jpg.c
+++ b/ff2jpg.c
_AT_@ -87,14 +87,8 @@ main(int argc, char *argv[])
fprintf(stderr, "%s: invalid magic value\n", argv0);
return 1;
}
- if (!(width = ntohl(hdr[2]))) {
- fprintf(stderr, "%s: invalid width: zero\n", argv0);
- return 1;
- }
- if (!(height = ntohl(hdr[3]))) {
- fprintf(stderr, "%s: invalid height: zero\n", argv0);
- return 1;
- }
+ width = ntohl(hdr[2]);
+ height = ntohl(hdr[3]);
if (width > SIZE_MAX / ((sizeof("RGBA") - 1) * sizeof(uint16_t))) {
fprintf(stderr, "%s: row length integer overflow\n", argv0);
diff --git a/ff2ppm.c b/ff2ppm.c
index 83b059e..880fa5b 100644
--- a/ff2ppm.c
+++ b/ff2ppm.c
_AT_@ -67,14 +67,8 @@ main(int argc, char *argv[])
fprintf(stderr, "%s: invalid magic value\n", argv0);
return 1;
}
- if (!(width = ntohl(hdr[2]))) {
- fprintf(stderr, "%s: invalid width: zero\n", argv0);
- return 1;
- }
- if (!(height = ntohl(hdr[3]))) {
- fprintf(stderr, "%s: invalid height: zero\n", argv0);
- return 1;
- }
+ width = ntohl(hdr[2]);
+ height = ntohl(hdr[3]);
if (width > SIZE_MAX / ((sizeof("RGBA") - 1) * sizeof(uint16_t))) {
fprintf(stderr, "%s: row length integer overflow\n", argv0);
Received on Sun Apr 10 2016 - 22:59:28 CEST
This archive was generated by hypermail 2.3.0
: Sun Apr 10 2016 - 23:00:16 CEST