Skip to content
Myr

fix bug where we couldn't rewind a file that reached EOF, which can happen with < 92-byte PIC,PNM,HDR,TGA

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Sean Barrett · committed by Sean Barrett · parent 28a29dd · Browse files · 2 files+27 added−10 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+27 added−10 removed

  • tests:+3 added−0 removed
  • other:+24 added−10 removed

2 files+27 added−10 removed

modified:tests/image_test.c+3 added
71 unmodified lines
72 if (argc > 1) {73 int i, n;7475 for (i=1; i < argc; ++i) {76 int res;77 unsigned char *data;78 printf("%s\n", argv[i]);79 res = stbi_info(argv[1], &w, &h, &n);80 data = stbi_load(argv[i], &w, &h, &n, 4); if (data) free(data); else printf("Failed &n\n");81 data = stbi_load(argv[i], &w, &h, 0, 1); if (data) free(data); else printf("Failed 1\n");82 data = stbi_load(argv[i], &w, &h, 0, 2); if (data) free(data); else printf("Failed 2\n");83 data = stbi_load(argv[i], &w, &h, 0, 3); if (data) free(data); else printf("Failed 3\n");84 data = stbi_load(argv[i], &w, &h, 0, 4);85 assert(data);86 assert(res);87 if (data) {88 char fname[512];89 stb_splitpath(fname, argv[i], STB_FILE);90 stbi_write_png(stb_sprintf("output/%s.png", fname), w, h, 4, data, w*4);
62 unmodified lines
modified:stb_image.h+24 added-10 removed
144 unmodified lines
145 near-term back-compatibility use.146147148 Latest revision history:149 2.07 (2015-09-13) fix compiler warnings; animated GIF support close;150 limited 16-bit PSD support; #ifdef unused functions149 2.07 (2015-09-13) partial animated GIF support150 limited 16-bit PSD support151 minor bugs, code cleanup, and compiler warnings152 2.06 (2015-04-19) fix bug where PSD returns wrong '*comp' value153 2.05 (2015-04-19) fix bug in progressive JPEG handling, fix warning154 2.04 (2015-04-15) try to re-enable SIMD on MinGW 64-bit155 2.03 (2015-04-12) additional corruption checking
601 unmodified lines
757 int buflen;758 stbi_uc buffer_start[128];759760 stbi_uc *img_buffer, *img_buffer_end;760 stbi_uc *img_buffer_original;761 stbi_uc *img_buffer_original, *img_buffer_original_end;762} stbi__context;763764765static void stbi__refill_buffer(stbi__context *s);
3 unmodified lines
769{770 s->io.read = NULL;771 s->read_from_callbacks = 0;772 s->img_buffer = s->img_buffer_original = (stbi_uc *) buffer;772 s->img_buffer_end = (stbi_uc *) buffer+len;773 s->img_buffer_end = s->img_buffer_original_end = (stbi_uc *) buffer+len;774}775776// initialize a callback-based context777static void stbi__start_callbacks(stbi__context *s, stbi_io_callbacks *c, void *user)
3 unmodified lines
781 s->buflen = sizeof(s->buffer_start);782 s->read_from_callbacks = 1;783 s->img_buffer_original = s->buffer_start;784 stbi__refill_buffer(s);785 s->img_buffer_original_end = s->img_buffer_end;786}787788#ifndef STBI_NO_STDIO789
33 unmodified lines
823 // conceptually rewind SHOULD rewind to the beginning of the stream,824 // but we just rewind to the beginning of the initial buffer, because825 // we only use it after doing 'test', which only ever looks at at most 92 bytes826 s->img_buffer = s->img_buffer_original;827 s->img_buffer_end = s->img_buffer_original_end;828}829830#ifndef STBI_NO_JPEG831static int stbi__jpeg_test(stbi__context *s);
5281 unmodified lines
6113{6114 int act_comp=0,num_packets=0,chained;6115 stbi__pic_packet packets[10];61166114 stbi__skip(s, 92);6117 if (!stbi__pic_is4(s,"\x53\x80\xF6\x34")) {6118 stbi__rewind(s);6119 return 0;6120 }61216122 stbi__skip(s, 88);61236124 *x = stbi__get16be(s);6125 *y = stbi__get16be(s);6118 if (stbi__at_eof(s)) return 0;6126 if (stbi__at_eof(s)) {6127 stbi__rewind( s);6128 return 0;6129 }6130 if ( (*x) != 0 && (1 << 28) / (*x) < (*y)) {6120 stbi__rewind( s );6121 return 0;6131 stbi__rewind( s );6132 return 0;6133 }61346135 stbi__skip(s, 8);6136
217 unmodified lines
6354#endif // STB_IMAGE_IMPLEMENTATION63556356/*6357 revision history:6347 2.07 (2015-09-13) fix compiler warnings; animated GIF support;6348 limited 16-bit PSD support; #ifdef unused functions6358 2.07 (2015-09-13) fix compiler warnings6359 partial animated GIF support6360 limited 16-bit PSD support6361 #ifdef unused functions6362 bug with < 92 byte PIC,PNM,HDR,TGA6363 2.06 (2015-04-19) fix bug where PSD returns wrong '*comp' value6364 2.05 (2015-04-19) fix bug in progressive JPEG handling, fix warning6365 2.04 (2015-04-15) try to re-enable SIMD on MinGW 64-bit6366 2.03 (2015-04-12) extra corruption checking (mmozeiko)
136 unmodified lines