Revision: 75565
http://sourceforge.net/p/brlcad/code/75565
Author: brlcad
Date: 2020-04-23 03:07:09 +0000 (Thu, 23 Apr 2020)
Log Message:
-----------
fix a bug reported by russell where bw-png was writing out corrupt pngs with
extra carriage returns embedded. this is due to the utility, like many others,
not setting binary-mode (O_BINARY) explicitly before writing binary to stdout.
needs comprehensive audit as, at glance, there are dozens of other utilities
that still don't (and are thus broken on Windows).
Modified Paths:
--------------
brlcad/trunk/src/util/bw-png.c
Modified: brlcad/trunk/src/util/bw-png.c
===================================================================
--- brlcad/trunk/src/util/bw-png.c 2020-04-23 02:32:31 UTC (rev 75564)
+++ brlcad/trunk/src/util/bw-png.c 2020-04-23 03:07:09 UTC (rev 75565)
@@ -112,6 +112,7 @@
unsigned char **rows;
png_structp png_p;
png_infop info_p;
+ FILE *outfp = stdout;
if (!get_args(argc, argv)) {
(void)fputs(usage, stderr);
@@ -129,6 +130,13 @@
}
}
+ setmode(fileno(outfp), O_BINARY);
+
+ if (isatty(fileno(outfp))) {
+ fprintf(stderr, "cv: trying to send binary output to terminal\n");
+ return 5;
+ }
+
png_p = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!png_p)
bu_exit(EXIT_FAILURE, "Could not create PNG write structure\n");
@@ -149,7 +157,7 @@
if (fread(scanbuf, SIZE, 1, infp) != 1)
bu_exit(EXIT_FAILURE, "bw-png: Short read\n");
- png_init_io(png_p, stdout);
+ png_init_io(png_p, outfp);
png_set_filter(png_p, 0, PNG_FILTER_NONE);
png_set_compression_level(png_p, 9);
png_set_IHDR(png_p, info_p, file_width, file_height, 8,
@@ -159,6 +167,10 @@
png_write_info(png_p, info_p);
png_write_image(png_p, rows);
png_write_end(png_p, NULL);
+
+ if (outfp != stdout)
+ fclose(outfp);
+
return 0;
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits