gosu 1.4.5 → 1.4.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +0 -8
  3. data/dependencies/SDL/include/SDL.h +1 -1
  4. data/dependencies/SDL/include/SDL_assert.h +4 -10
  5. data/dependencies/SDL/include/SDL_atomic.h +1 -1
  6. data/dependencies/SDL/include/SDL_audio.h +1 -1
  7. data/dependencies/SDL/include/SDL_bits.h +1 -1
  8. data/dependencies/SDL/include/SDL_blendmode.h +1 -1
  9. data/dependencies/SDL/include/SDL_clipboard.h +1 -1
  10. data/dependencies/SDL/include/SDL_config.h +2 -2
  11. data/dependencies/SDL/include/SDL_cpuinfo.h +1 -1
  12. data/dependencies/SDL/include/SDL_egl.h +1 -1
  13. data/dependencies/SDL/include/SDL_endian.h +1 -1
  14. data/dependencies/SDL/include/SDL_error.h +1 -1
  15. data/dependencies/SDL/include/SDL_events.h +1 -1
  16. data/dependencies/SDL/include/SDL_filesystem.h +1 -1
  17. data/dependencies/SDL/include/SDL_gamecontroller.h +1 -1
  18. data/dependencies/SDL/include/SDL_gesture.h +1 -1
  19. data/dependencies/SDL/include/SDL_guid.h +1 -1
  20. data/dependencies/SDL/include/SDL_haptic.h +1 -1
  21. data/dependencies/SDL/include/SDL_hidapi.h +1 -1
  22. data/dependencies/SDL/include/SDL_hints.h +1 -1
  23. data/dependencies/SDL/include/SDL_joystick.h +1 -1
  24. data/dependencies/SDL/include/SDL_keyboard.h +1 -1
  25. data/dependencies/SDL/include/SDL_keycode.h +1 -1
  26. data/dependencies/SDL/include/SDL_loadso.h +1 -1
  27. data/dependencies/SDL/include/SDL_locale.h +1 -1
  28. data/dependencies/SDL/include/SDL_log.h +1 -1
  29. data/dependencies/SDL/include/SDL_main.h +1 -1
  30. data/dependencies/SDL/include/SDL_messagebox.h +1 -1
  31. data/dependencies/SDL/include/SDL_metal.h +1 -1
  32. data/dependencies/SDL/include/SDL_misc.h +1 -1
  33. data/dependencies/SDL/include/SDL_mouse.h +1 -1
  34. data/dependencies/SDL/include/SDL_mutex.h +1 -1
  35. data/dependencies/SDL/include/SDL_name.h +1 -1
  36. data/dependencies/SDL/include/SDL_opengl.h +1 -1
  37. data/dependencies/SDL/include/SDL_opengles.h +1 -1
  38. data/dependencies/SDL/include/SDL_opengles2.h +1 -1
  39. data/dependencies/SDL/include/SDL_pixels.h +1 -1
  40. data/dependencies/SDL/include/SDL_platform.h +1 -1
  41. data/dependencies/SDL/include/SDL_power.h +1 -1
  42. data/dependencies/SDL/include/SDL_quit.h +1 -1
  43. data/dependencies/SDL/include/SDL_rect.h +1 -1
  44. data/dependencies/SDL/include/SDL_render.h +1 -1
  45. data/dependencies/SDL/include/SDL_revision.h +2 -2
  46. data/dependencies/SDL/include/SDL_rwops.h +1 -1
  47. data/dependencies/SDL/include/SDL_scancode.h +1 -1
  48. data/dependencies/SDL/include/SDL_sensor.h +1 -1
  49. data/dependencies/SDL/include/SDL_shape.h +1 -1
  50. data/dependencies/SDL/include/SDL_stdinc.h +1 -1
  51. data/dependencies/SDL/include/SDL_surface.h +1 -1
  52. data/dependencies/SDL/include/SDL_system.h +1 -1
  53. data/dependencies/SDL/include/SDL_syswm.h +1 -1
  54. data/dependencies/SDL/include/SDL_test.h +1 -1
  55. data/dependencies/SDL/include/SDL_test_assert.h +1 -1
  56. data/dependencies/SDL/include/SDL_test_common.h +1 -1
  57. data/dependencies/SDL/include/SDL_test_compare.h +1 -1
  58. data/dependencies/SDL/include/SDL_test_crc32.h +1 -1
  59. data/dependencies/SDL/include/SDL_test_font.h +1 -1
  60. data/dependencies/SDL/include/SDL_test_fuzzer.h +1 -1
  61. data/dependencies/SDL/include/SDL_test_harness.h +1 -1
  62. data/dependencies/SDL/include/SDL_test_images.h +1 -1
  63. data/dependencies/SDL/include/SDL_test_log.h +1 -1
  64. data/dependencies/SDL/include/SDL_test_md5.h +1 -1
  65. data/dependencies/SDL/include/SDL_test_memory.h +1 -1
  66. data/dependencies/SDL/include/SDL_test_random.h +1 -1
  67. data/dependencies/SDL/include/SDL_thread.h +3 -3
  68. data/dependencies/SDL/include/SDL_timer.h +1 -1
  69. data/dependencies/SDL/include/SDL_touch.h +1 -1
  70. data/dependencies/SDL/include/SDL_types.h +1 -1
  71. data/dependencies/SDL/include/SDL_version.h +2 -2
  72. data/dependencies/SDL/include/SDL_video.h +1 -1
  73. data/dependencies/SDL/include/begin_code.h +1 -1
  74. data/dependencies/SDL/include/close_code.h +1 -1
  75. data/dependencies/SDL/lib/x64/libSDL2.dll.a +0 -0
  76. data/dependencies/SDL/lib/x86/libSDL2.dll.a +0 -0
  77. data/dependencies/SDL_sound/SDL_sound_internal.h +3 -3
  78. data/dependencies/SDL_sound/SDL_sound_wav.c +5 -0
  79. data/dependencies/mojoAL/mojoal.c +41 -30
  80. data/dependencies/stb/stb_image.h +117 -27
  81. data/ext/gosu/extconf.rb +1 -1
  82. data/include/Gosu/Version.hpp +1 -1
  83. data/lib/SDL2.dll +0 -0
  84. data/lib64/SDL2.dll +0 -0
  85. data/src/AudioFile.hpp +1 -1
  86. data/src/AudioFileSDLSound.cpp +2 -0
  87. data/src/AudioImpl.hpp +2 -2
  88. data/src/Input.cpp +30 -26
  89. data/src/RubyGosu.cxx +146 -93
  90. data/src/RubyGosu.h +5 -7
  91. metadata +3 -13
  92. data/dependencies/SDL/include/SDL_config_android.h +0 -157
  93. data/dependencies/SDL/include/SDL_config_iphoneos.h +0 -166
  94. data/dependencies/SDL/include/SDL_config_macosx.h +0 -197
  95. data/dependencies/SDL/include/SDL_config_minimal.h +0 -82
  96. data/dependencies/SDL/include/SDL_config_pandora.h +0 -128
  97. data/dependencies/SDL/include/SDL_config_psp.h +0 -144
  98. data/dependencies/SDL/include/SDL_config_windows.h +0 -225
  99. data/dependencies/SDL/include/SDL_config_winrt.h +0 -215
  100. data/dependencies/SDL/include/SDL_config_wiz.h +0 -121
  101. data/dependencies/SDL/include/SDL_copying.h +0 -20
@@ -1,4 +1,4 @@
1
- /* stb_image - v2.27 - public domain image loader - http://nothings.org/stb
1
+ /* stb_image - v2.28 - public domain image loader - http://nothings.org/stb
2
2
  no warranty implied; use at your own risk
3
3
 
4
4
  Do this:
@@ -48,6 +48,7 @@ LICENSE
48
48
 
49
49
  RECENT REVISION HISTORY:
50
50
 
51
+ 2.28 (2023-01-29) many error fixes, security errors, just tons of stuff
51
52
  2.27 (2021-07-11) document stbi_info better, 16-bit PNM support, bug fixes
52
53
  2.26 (2020-07-13) many minor fixes
53
54
  2.25 (2020-02-02) fix warnings
@@ -108,7 +109,7 @@ RECENT REVISION HISTORY:
108
109
  Cass Everitt Ryamond Barbiero github:grim210
109
110
  Paul Du Bois Engin Manap Aldo Culquicondor github:sammyhw
110
111
  Philipp Wiesemann Dale Weiler Oriol Ferrer Mesia github:phprus
111
- Josh Tobin Matthew Gregan github:poppolopoppo
112
+ Josh Tobin Neil Bickford Matthew Gregan github:poppolopoppo
112
113
  Julian Raschke Gregory Mullen Christian Floisand github:darealshinji
113
114
  Baldur Karlsson Kevin Schmidt JR Smith github:Michaelangel007
114
115
  Brad Weinberger Matvey Cherevko github:mosra
@@ -140,7 +141,7 @@ RECENT REVISION HISTORY:
140
141
  // // ... x = width, y = height, n = # 8-bit components per pixel ...
141
142
  // // ... replace '0' with '1'..'4' to force that many components per pixel
142
143
  // // ... but 'n' will always be the number that it would have been if you said 0
143
- // stbi_image_free(data)
144
+ // stbi_image_free(data);
144
145
  //
145
146
  // Standard parameters:
146
147
  // int *x -- outputs image width in pixels
@@ -635,7 +636,7 @@ STBIDEF int stbi_zlib_decode_noheader_buffer(char *obuffer, int olen, const ch
635
636
  #endif
636
637
  #endif
637
638
 
638
- #ifdef _MSC_VER
639
+ #if defined(_MSC_VER) || defined(__SYMBIAN32__)
639
640
  typedef unsigned short stbi__uint16;
640
641
  typedef signed short stbi__int16;
641
642
  typedef unsigned int stbi__uint32;
@@ -1063,6 +1064,23 @@ static void *stbi__malloc_mad4(int a, int b, int c, int d, int add)
1063
1064
  }
1064
1065
  #endif
1065
1066
 
1067
+ // returns 1 if the sum of two signed ints is valid (between -2^31 and 2^31-1 inclusive), 0 on overflow.
1068
+ static int stbi__addints_valid(int a, int b)
1069
+ {
1070
+ if ((a >= 0) != (b >= 0)) return 1; // a and b have different signs, so no overflow
1071
+ if (a < 0 && b < 0) return a >= INT_MIN - b; // same as a + b >= INT_MIN; INT_MIN - b cannot overflow since b < 0.
1072
+ return a <= INT_MAX - b;
1073
+ }
1074
+
1075
+ // returns 1 if the product of two signed shorts is valid, 0 on overflow.
1076
+ static int stbi__mul2shorts_valid(short a, short b)
1077
+ {
1078
+ if (b == 0 || b == -1) return 1; // multiplication by 0 is always 0; check for -1 so SHRT_MIN/b doesn't overflow
1079
+ if ((a >= 0) == (b >= 0)) return a <= SHRT_MAX/b; // product is positive, so similar to mul2sizes_valid
1080
+ if (b < 0) return a <= SHRT_MIN / b; // same as a * b >= SHRT_MIN
1081
+ return a >= SHRT_MIN / b;
1082
+ }
1083
+
1066
1084
  // stbi__err - error
1067
1085
  // stbi__errpf - error returning pointer to float
1068
1086
  // stbi__errpuc - error returning pointer to unsigned char
@@ -1985,9 +2003,12 @@ static int stbi__build_huffman(stbi__huffman *h, int *count)
1985
2003
  int i,j,k=0;
1986
2004
  unsigned int code;
1987
2005
  // build size list for each symbol (from JPEG spec)
1988
- for (i=0; i < 16; ++i)
1989
- for (j=0; j < count[i]; ++j)
2006
+ for (i=0; i < 16; ++i) {
2007
+ for (j=0; j < count[i]; ++j) {
1990
2008
  h->size[k++] = (stbi_uc) (i+1);
2009
+ if(k >= 257) return stbi__err("bad size list","Corrupt JPEG");
2010
+ }
2011
+ }
1991
2012
  h->size[k] = 0;
1992
2013
 
1993
2014
  // compute actual symbols (from jpeg spec)
@@ -2112,6 +2133,8 @@ stbi_inline static int stbi__jpeg_huff_decode(stbi__jpeg *j, stbi__huffman *h)
2112
2133
 
2113
2134
  // convert the huffman code to the symbol id
2114
2135
  c = ((j->code_buffer >> (32 - k)) & stbi__bmask[k]) + h->delta[k];
2136
+ if(c < 0 || c >= 256) // symbol id out of bounds!
2137
+ return -1;
2115
2138
  STBI_ASSERT((((j->code_buffer) >> (32 - h->size[c])) & stbi__bmask[h->size[c]]) == h->code[c]);
2116
2139
 
2117
2140
  // convert the id to a symbol
@@ -2130,6 +2153,7 @@ stbi_inline static int stbi__extend_receive(stbi__jpeg *j, int n)
2130
2153
  unsigned int k;
2131
2154
  int sgn;
2132
2155
  if (j->code_bits < n) stbi__grow_buffer_unsafe(j);
2156
+ if (j->code_bits < n) return 0; // ran out of bits from stream, return 0s intead of continuing
2133
2157
 
2134
2158
  sgn = j->code_buffer >> 31; // sign bit always in MSB; 0 if MSB clear (positive), 1 if MSB set (negative)
2135
2159
  k = stbi_lrot(j->code_buffer, n);
@@ -2144,6 +2168,7 @@ stbi_inline static int stbi__jpeg_get_bits(stbi__jpeg *j, int n)
2144
2168
  {
2145
2169
  unsigned int k;
2146
2170
  if (j->code_bits < n) stbi__grow_buffer_unsafe(j);
2171
+ if (j->code_bits < n) return 0; // ran out of bits from stream, return 0s intead of continuing
2147
2172
  k = stbi_lrot(j->code_buffer, n);
2148
2173
  j->code_buffer = k & ~stbi__bmask[n];
2149
2174
  k &= stbi__bmask[n];
@@ -2155,6 +2180,7 @@ stbi_inline static int stbi__jpeg_get_bit(stbi__jpeg *j)
2155
2180
  {
2156
2181
  unsigned int k;
2157
2182
  if (j->code_bits < 1) stbi__grow_buffer_unsafe(j);
2183
+ if (j->code_bits < 1) return 0; // ran out of bits from stream, return 0s intead of continuing
2158
2184
  k = j->code_buffer;
2159
2185
  j->code_buffer <<= 1;
2160
2186
  --j->code_bits;
@@ -2192,8 +2218,10 @@ static int stbi__jpeg_decode_block(stbi__jpeg *j, short data[64], stbi__huffman
2192
2218
  memset(data,0,64*sizeof(data[0]));
2193
2219
 
2194
2220
  diff = t ? stbi__extend_receive(j, t) : 0;
2221
+ if (!stbi__addints_valid(j->img_comp[b].dc_pred, diff)) return stbi__err("bad delta","Corrupt JPEG");
2195
2222
  dc = j->img_comp[b].dc_pred + diff;
2196
2223
  j->img_comp[b].dc_pred = dc;
2224
+ if (!stbi__mul2shorts_valid(dc, dequant[0])) return stbi__err("can't merge dc and ac", "Corrupt JPEG");
2197
2225
  data[0] = (short) (dc * dequant[0]);
2198
2226
 
2199
2227
  // decode AC components, see JPEG spec
@@ -2207,6 +2235,7 @@ static int stbi__jpeg_decode_block(stbi__jpeg *j, short data[64], stbi__huffman
2207
2235
  if (r) { // fast-AC path
2208
2236
  k += (r >> 4) & 15; // run
2209
2237
  s = r & 15; // combined length
2238
+ if (s > j->code_bits) return stbi__err("bad huffman code", "Combined length longer than code bits available");
2210
2239
  j->code_buffer <<= s;
2211
2240
  j->code_bits -= s;
2212
2241
  // decode into unzigzag'd location
@@ -2246,8 +2275,10 @@ static int stbi__jpeg_decode_block_prog_dc(stbi__jpeg *j, short data[64], stbi__
2246
2275
  if (t < 0 || t > 15) return stbi__err("can't merge dc and ac", "Corrupt JPEG");
2247
2276
  diff = t ? stbi__extend_receive(j, t) : 0;
2248
2277
 
2278
+ if (!stbi__addints_valid(j->img_comp[b].dc_pred, diff)) return stbi__err("bad delta", "Corrupt JPEG");
2249
2279
  dc = j->img_comp[b].dc_pred + diff;
2250
2280
  j->img_comp[b].dc_pred = dc;
2281
+ if (!stbi__mul2shorts_valid(dc, 1 << j->succ_low)) return stbi__err("can't merge dc and ac", "Corrupt JPEG");
2251
2282
  data[0] = (short) (dc * (1 << j->succ_low));
2252
2283
  } else {
2253
2284
  // refinement scan for DC coefficient
@@ -2282,6 +2313,7 @@ static int stbi__jpeg_decode_block_prog_ac(stbi__jpeg *j, short data[64], stbi__
2282
2313
  if (r) { // fast-AC path
2283
2314
  k += (r >> 4) & 15; // run
2284
2315
  s = r & 15; // combined length
2316
+ if (s > j->code_bits) return stbi__err("bad huffman code", "Combined length longer than code bits available");
2285
2317
  j->code_buffer <<= s;
2286
2318
  j->code_bits -= s;
2287
2319
  zig = stbi__jpeg_dezigzag[k++];
@@ -3102,6 +3134,7 @@ static int stbi__process_marker(stbi__jpeg *z, int m)
3102
3134
  sizes[i] = stbi__get8(z->s);
3103
3135
  n += sizes[i];
3104
3136
  }
3137
+ if(n > 256) return stbi__err("bad DHT header","Corrupt JPEG"); // Loop over i < n would write past end of values!
3105
3138
  L -= 17;
3106
3139
  if (tc == 0) {
3107
3140
  if (!stbi__build_huffman(z->huff_dc+th, sizes)) return 0;
@@ -3351,6 +3384,28 @@ static int stbi__decode_jpeg_header(stbi__jpeg *z, int scan)
3351
3384
  return 1;
3352
3385
  }
3353
3386
 
3387
+ static int stbi__skip_jpeg_junk_at_end(stbi__jpeg *j)
3388
+ {
3389
+ // some JPEGs have junk at end, skip over it but if we find what looks
3390
+ // like a valid marker, resume there
3391
+ while (!stbi__at_eof(j->s)) {
3392
+ int x = stbi__get8(j->s);
3393
+ while (x == 255) { // might be a marker
3394
+ if (stbi__at_eof(j->s)) return STBI__MARKER_none;
3395
+ x = stbi__get8(j->s);
3396
+ if (x != 0x00 && x != 0xff) {
3397
+ // not a stuffed zero or lead-in to another marker, looks
3398
+ // like an actual marker, return it
3399
+ return x;
3400
+ }
3401
+ // stuffed zero has x=0 now which ends the loop, meaning we go
3402
+ // back to regular scan loop.
3403
+ // repeated 0xff keeps trying to read the next byte of the marker.
3404
+ }
3405
+ }
3406
+ return STBI__MARKER_none;
3407
+ }
3408
+
3354
3409
  // decode image to YCbCr format
3355
3410
  static int stbi__decode_jpeg_image(stbi__jpeg *j)
3356
3411
  {
@@ -3367,25 +3422,22 @@ static int stbi__decode_jpeg_image(stbi__jpeg *j)
3367
3422
  if (!stbi__process_scan_header(j)) return 0;
3368
3423
  if (!stbi__parse_entropy_coded_data(j)) return 0;
3369
3424
  if (j->marker == STBI__MARKER_none ) {
3370
- // handle 0s at the end of image data from IP Kamera 9060
3371
- while (!stbi__at_eof(j->s)) {
3372
- int x = stbi__get8(j->s);
3373
- if (x == 255) {
3374
- j->marker = stbi__get8(j->s);
3375
- break;
3376
- }
3377
- }
3425
+ j->marker = stbi__skip_jpeg_junk_at_end(j);
3378
3426
  // if we reach eof without hitting a marker, stbi__get_marker() below will fail and we'll eventually return 0
3379
3427
  }
3428
+ m = stbi__get_marker(j);
3429
+ if (STBI__RESTART(m))
3430
+ m = stbi__get_marker(j);
3380
3431
  } else if (stbi__DNL(m)) {
3381
3432
  int Ld = stbi__get16be(j->s);
3382
3433
  stbi__uint32 NL = stbi__get16be(j->s);
3383
3434
  if (Ld != 4) return stbi__err("bad DNL len", "Corrupt JPEG");
3384
3435
  if (NL != j->s->img_y) return stbi__err("bad DNL height", "Corrupt JPEG");
3436
+ m = stbi__get_marker(j);
3385
3437
  } else {
3386
- if (!stbi__process_marker(j, m)) return 0;
3438
+ if (!stbi__process_marker(j, m)) return 1;
3439
+ m = stbi__get_marker(j);
3387
3440
  }
3388
- m = stbi__get_marker(j);
3389
3441
  }
3390
3442
  if (j->progressive)
3391
3443
  stbi__jpeg_finish(j);
@@ -3976,6 +4028,7 @@ static void *stbi__jpeg_load(stbi__context *s, int *x, int *y, int *comp, int re
3976
4028
  unsigned char* result;
3977
4029
  stbi__jpeg* j = (stbi__jpeg*) stbi__malloc(sizeof(stbi__jpeg));
3978
4030
  if (!j) return stbi__errpuc("outofmem", "Out of memory");
4031
+ memset(j, 0, sizeof(stbi__jpeg));
3979
4032
  STBI_NOTUSED(ri);
3980
4033
  j->s = s;
3981
4034
  stbi__setup_jpeg(j);
@@ -3989,6 +4042,7 @@ static int stbi__jpeg_test(stbi__context *s)
3989
4042
  int r;
3990
4043
  stbi__jpeg* j = (stbi__jpeg*)stbi__malloc(sizeof(stbi__jpeg));
3991
4044
  if (!j) return stbi__err("outofmem", "Out of memory");
4045
+ memset(j, 0, sizeof(stbi__jpeg));
3992
4046
  j->s = s;
3993
4047
  stbi__setup_jpeg(j);
3994
4048
  r = stbi__decode_jpeg_header(j, STBI__SCAN_type);
@@ -4014,6 +4068,7 @@ static int stbi__jpeg_info(stbi__context *s, int *x, int *y, int *comp)
4014
4068
  int result;
4015
4069
  stbi__jpeg* j = (stbi__jpeg*) (stbi__malloc(sizeof(stbi__jpeg)));
4016
4070
  if (!j) return stbi__err("outofmem", "Out of memory");
4071
+ memset(j, 0, sizeof(stbi__jpeg));
4017
4072
  j->s = s;
4018
4073
  result = stbi__jpeg_info_raw(j, x, y, comp);
4019
4074
  STBI_FREE(j);
@@ -4256,11 +4311,12 @@ static int stbi__parse_huffman_block(stbi__zbuf *a)
4256
4311
  a->zout = zout;
4257
4312
  return 1;
4258
4313
  }
4314
+ if (z >= 286) return stbi__err("bad huffman code","Corrupt PNG"); // per DEFLATE, length codes 286 and 287 must not appear in compressed data
4259
4315
  z -= 257;
4260
4316
  len = stbi__zlength_base[z];
4261
4317
  if (stbi__zlength_extra[z]) len += stbi__zreceive(a, stbi__zlength_extra[z]);
4262
4318
  z = stbi__zhuffman_decode(a, &a->z_distance);
4263
- if (z < 0) return stbi__err("bad huffman code","Corrupt PNG");
4319
+ if (z < 0 || z >= 30) return stbi__err("bad huffman code","Corrupt PNG"); // per DEFLATE, distance codes 30 and 31 must not appear in compressed data
4264
4320
  dist = stbi__zdist_base[z];
4265
4321
  if (stbi__zdist_extra[z]) dist += stbi__zreceive(a, stbi__zdist_extra[z]);
4266
4322
  if (zout - a->zout_start < dist) return stbi__err("bad dist","Corrupt PNG");
@@ -4955,7 +5011,7 @@ STBIDEF void stbi_convert_iphone_png_to_rgb(int flag_true_if_should_convert)
4955
5011
  static STBI_THREAD_LOCAL int stbi__unpremultiply_on_load_local, stbi__unpremultiply_on_load_set;
4956
5012
  static STBI_THREAD_LOCAL int stbi__de_iphone_flag_local, stbi__de_iphone_flag_set;
4957
5013
 
4958
- STBIDEF void stbi__unpremultiply_on_load_thread(int flag_true_if_should_unpremultiply)
5014
+ STBIDEF void stbi_set_unpremultiply_on_load_thread(int flag_true_if_should_unpremultiply)
4959
5015
  {
4960
5016
  stbi__unpremultiply_on_load_local = flag_true_if_should_unpremultiply;
4961
5017
  stbi__unpremultiply_on_load_set = 1;
@@ -5064,14 +5120,13 @@ static int stbi__parse_png_file(stbi__png *z, int scan, int req_comp)
5064
5120
  if (!pal_img_n) {
5065
5121
  s->img_n = (color & 2 ? 3 : 1) + (color & 4 ? 1 : 0);
5066
5122
  if ((1 << 30) / s->img_x / s->img_n < s->img_y) return stbi__err("too large", "Image too large to decode");
5067
- if (scan == STBI__SCAN_header) return 1;
5068
5123
  } else {
5069
5124
  // if paletted, then pal_n is our final components, and
5070
5125
  // img_n is # components to decompress/filter.
5071
5126
  s->img_n = 1;
5072
5127
  if ((1 << 30) / s->img_x / 4 < s->img_y) return stbi__err("too large","Corrupt PNG");
5073
- // if SCAN_header, have to scan to see if we have a tRNS
5074
5128
  }
5129
+ // even with SCAN_header, have to scan to see if we have a tRNS
5075
5130
  break;
5076
5131
  }
5077
5132
 
@@ -5103,6 +5158,8 @@ static int stbi__parse_png_file(stbi__png *z, int scan, int req_comp)
5103
5158
  if (!(s->img_n & 1)) return stbi__err("tRNS with alpha","Corrupt PNG");
5104
5159
  if (c.length != (stbi__uint32) s->img_n*2) return stbi__err("bad tRNS len","Corrupt PNG");
5105
5160
  has_trans = 1;
5161
+ // non-paletted with tRNS = constant alpha. if header-scanning, we can stop now.
5162
+ if (scan == STBI__SCAN_header) { ++s->img_n; return 1; }
5106
5163
  if (z->depth == 16) {
5107
5164
  for (k = 0; k < s->img_n; ++k) tc16[k] = (stbi__uint16)stbi__get16be(s); // copy the values as-is
5108
5165
  } else {
@@ -5115,7 +5172,13 @@ static int stbi__parse_png_file(stbi__png *z, int scan, int req_comp)
5115
5172
  case STBI__PNG_TYPE('I','D','A','T'): {
5116
5173
  if (first) return stbi__err("first not IHDR", "Corrupt PNG");
5117
5174
  if (pal_img_n && !pal_len) return stbi__err("no PLTE","Corrupt PNG");
5118
- if (scan == STBI__SCAN_header) { s->img_n = pal_img_n; return 1; }
5175
+ if (scan == STBI__SCAN_header) {
5176
+ // header scan definitely stops at first IDAT
5177
+ if (pal_img_n)
5178
+ s->img_n = pal_img_n;
5179
+ return 1;
5180
+ }
5181
+ if (c.length > (1u << 30)) return stbi__err("IDAT size limit", "IDAT section larger than 2^30 bytes");
5119
5182
  if ((int)(ioff + c.length) < (int)ioff) return 0;
5120
5183
  if (ioff + c.length > idata_limit) {
5121
5184
  stbi__uint32 idata_limit_old = idata_limit;
@@ -5498,8 +5561,22 @@ static void *stbi__bmp_load(stbi__context *s, int *x, int *y, int *comp, int req
5498
5561
  psize = (info.offset - info.extra_read - info.hsz) >> 2;
5499
5562
  }
5500
5563
  if (psize == 0) {
5501
- if (info.offset != s->callback_already_read + (s->img_buffer - s->img_buffer_original)) {
5502
- return stbi__errpuc("bad offset", "Corrupt BMP");
5564
+ // accept some number of extra bytes after the header, but if the offset points either to before
5565
+ // the header ends or implies a large amount of extra data, reject the file as malformed
5566
+ int bytes_read_so_far = s->callback_already_read + (int)(s->img_buffer - s->img_buffer_original);
5567
+ int header_limit = 1024; // max we actually read is below 256 bytes currently.
5568
+ int extra_data_limit = 256*4; // what ordinarily goes here is a palette; 256 entries*4 bytes is its max size.
5569
+ if (bytes_read_so_far <= 0 || bytes_read_so_far > header_limit) {
5570
+ return stbi__errpuc("bad header", "Corrupt BMP");
5571
+ }
5572
+ // we established that bytes_read_so_far is positive and sensible.
5573
+ // the first half of this test rejects offsets that are either too small positives, or
5574
+ // negative, and guarantees that info.offset >= bytes_read_so_far > 0. this in turn
5575
+ // ensures the number computed in the second half of the test can't overflow.
5576
+ if (info.offset < bytes_read_so_far || info.offset - bytes_read_so_far > extra_data_limit) {
5577
+ return stbi__errpuc("bad offset", "Corrupt BMP");
5578
+ } else {
5579
+ stbi__skip(s, info.offset - bytes_read_so_far);
5503
5580
  }
5504
5581
  }
5505
5582
 
@@ -7187,12 +7264,12 @@ static float *stbi__hdr_load(stbi__context *s, int *x, int *y, int *comp, int re
7187
7264
  // Run
7188
7265
  value = stbi__get8(s);
7189
7266
  count -= 128;
7190
- if (count > nleft) { STBI_FREE(hdr_data); STBI_FREE(scanline); return stbi__errpf("corrupt", "bad RLE data in HDR"); }
7267
+ if ((count == 0) || (count > nleft)) { STBI_FREE(hdr_data); STBI_FREE(scanline); return stbi__errpf("corrupt", "bad RLE data in HDR"); }
7191
7268
  for (z = 0; z < count; ++z)
7192
7269
  scanline[i++ * 4 + k] = value;
7193
7270
  } else {
7194
7271
  // Dump
7195
- if (count > nleft) { STBI_FREE(hdr_data); STBI_FREE(scanline); return stbi__errpf("corrupt", "bad RLE data in HDR"); }
7272
+ if ((count == 0) || (count > nleft)) { STBI_FREE(hdr_data); STBI_FREE(scanline); return stbi__errpf("corrupt", "bad RLE data in HDR"); }
7196
7273
  for (z = 0; z < count; ++z)
7197
7274
  scanline[i++ * 4 + k] = stbi__get8(s);
7198
7275
  }
@@ -7446,10 +7523,17 @@ static void *stbi__pnm_load(stbi__context *s, int *x, int *y, int *comp, int req
7446
7523
 
7447
7524
  out = (stbi_uc *) stbi__malloc_mad4(s->img_n, s->img_x, s->img_y, ri->bits_per_channel / 8, 0);
7448
7525
  if (!out) return stbi__errpuc("outofmem", "Out of memory");
7449
- stbi__getn(s, out, s->img_n * s->img_x * s->img_y * (ri->bits_per_channel / 8));
7526
+ if (!stbi__getn(s, out, s->img_n * s->img_x * s->img_y * (ri->bits_per_channel / 8))) {
7527
+ STBI_FREE(out);
7528
+ return stbi__errpuc("bad PNM", "PNM file truncated");
7529
+ }
7450
7530
 
7451
7531
  if (req_comp && req_comp != s->img_n) {
7452
- out = stbi__convert_format(out, s->img_n, req_comp, s->img_x, s->img_y);
7532
+ if (ri->bits_per_channel == 16) {
7533
+ out = (stbi_uc *) stbi__convert_format16((stbi__uint16 *) out, s->img_n, req_comp, s->img_x, s->img_y);
7534
+ } else {
7535
+ out = stbi__convert_format(out, s->img_n, req_comp, s->img_x, s->img_y);
7536
+ }
7453
7537
  if (out == NULL) return out; // stbi__convert_format frees input on failure
7454
7538
  }
7455
7539
  return out;
@@ -7486,6 +7570,8 @@ static int stbi__pnm_getinteger(stbi__context *s, char *c)
7486
7570
  while (!stbi__at_eof(s) && stbi__pnm_isdigit(*c)) {
7487
7571
  value = value*10 + (*c - '0');
7488
7572
  *c = (char) stbi__get8(s);
7573
+ if((value > 214748364) || (value == 214748364 && *c > '7'))
7574
+ return stbi__err("integer parse overflow", "Parsing an integer in the PPM header overflowed a 32-bit int");
7489
7575
  }
7490
7576
 
7491
7577
  return value;
@@ -7516,9 +7602,13 @@ static int stbi__pnm_info(stbi__context *s, int *x, int *y, int *comp)
7516
7602
  stbi__pnm_skip_whitespace(s, &c);
7517
7603
 
7518
7604
  *x = stbi__pnm_getinteger(s, &c); // read width
7605
+ if(*x == 0)
7606
+ return stbi__err("invalid width", "PPM image header had zero or overflowing width");
7519
7607
  stbi__pnm_skip_whitespace(s, &c);
7520
7608
 
7521
7609
  *y = stbi__pnm_getinteger(s, &c); // read height
7610
+ if (*y == 0)
7611
+ return stbi__err("invalid width", "PPM image header had zero or overflowing width");
7522
7612
  stbi__pnm_skip_whitespace(s, &c);
7523
7613
 
7524
7614
  maxv = stbi__pnm_getinteger(s, &c); // read max value
data/ext/gosu/extconf.rb CHANGED
@@ -33,7 +33,7 @@ $CXXFLAGS ||= ""
33
33
  $CXXFLAGS << " -std=gnu++17 -Dregister="
34
34
 
35
35
  # Make Gosu's own header files and all of its dependencies available to C++ source files.
36
- $INCFLAGS << " -I../../include -I../../dependencies/stb -I../../dependencies/utf8proc -I../../dependencies/SDL_sound -I../../dependencies/mojoAL"
36
+ $INCFLAGS << " -I../../include -I../../dependencies/stb -I../../dependencies/utf8proc -I../../dependencies/SDL_sound -I../../dependencies/mojoAL/AL"
37
37
 
38
38
  if windows
39
39
  # We statically compile utf8proc into the Gosu binary.
@@ -4,7 +4,7 @@
4
4
 
5
5
  #define GOSU_MAJOR_VERSION 1
6
6
  #define GOSU_MINOR_VERSION 4
7
- #define GOSU_POINT_VERSION 5
7
+ #define GOSU_POINT_VERSION 6
8
8
 
9
9
  namespace Gosu
10
10
  {
data/lib/SDL2.dll CHANGED
Binary file
data/lib64/SDL2.dll CHANGED
Binary file
data/src/AudioFile.hpp CHANGED
@@ -8,7 +8,7 @@
8
8
  #define OPENAL_DEPRECATED
9
9
  #include <OpenAL/al.h>
10
10
  #else
11
- #include <AL/al.h>
11
+ #include <al.h>
12
12
  #endif
13
13
 
14
14
  #include <cstddef>
@@ -12,7 +12,9 @@
12
12
  #include <algorithm>
13
13
  #include <memory>
14
14
  #include <mutex>
15
+ #include <stdexcept>
15
16
  #include <vector>
17
+ #include <stdexcept>
16
18
 
17
19
  struct Gosu::AudioFile::Impl : private Gosu::Noncopyable
18
20
  {
data/src/AudioImpl.hpp CHANGED
@@ -9,8 +9,8 @@
9
9
  #include <OpenAL/al.h>
10
10
  #include <OpenAL/alc.h>
11
11
  #else
12
- #include <AL/al.h>
13
- #include <AL/alc.h>
12
+ #include <al.h>
13
+ #include <alc.h>
14
14
  #endif
15
15
 
16
16
  namespace Gosu
data/src/Input.cpp CHANGED
@@ -13,6 +13,7 @@
13
13
  #include <algorithm>
14
14
  #include <array>
15
15
  #include <mutex>
16
+ #include <stdexcept>
16
17
  using namespace std;
17
18
 
18
19
  static void require_sdl_video()
@@ -140,39 +141,42 @@ struct Gosu::Input::Impl : private Gosu::Noncopyable
140
141
  }
141
142
  int gamepad_slot = -1;
142
143
  int joystick_instance_id = -1;
144
+ int i = e->jdevice.which; // SDL2 device_index
143
145
 
144
- // Loop through attached gamepads as e->jdevice.which cannot be trusted (always 0)
145
- for (int i = 0; i < SDL_NumJoysticks(); i++) {
146
- // Prefer the SDL_GameController API...
147
- if (SDL_IsGameController(i)) {
148
- if (SDL_GameController *game_controller = SDL_GameControllerOpen(i)) {
149
- gamepad_slot = available_gamepad_slot_index();
150
- joystick_instance_id = SDL_JoystickInstanceID(SDL_GameControllerGetJoystick(game_controller));
151
- if (gamepad_instance_id_is_known(joystick_instance_id)) {
152
- continue;
153
- }
154
- open_game_controllers.emplace_back(
155
- shared_ptr<SDL_GameController>(game_controller, SDL_GameControllerClose)
156
- );
157
- }
158
- }
159
- // ...but fall back on the good, old SDL_Joystick API.
160
- else if (SDL_Joystick *joystick = SDL_JoystickOpen(i)) {
146
+ if (SDL_IsGameController(i)) {
147
+ if (SDL_GameController *game_controller = SDL_GameControllerOpen(i)) {
161
148
  gamepad_slot = available_gamepad_slot_index();
162
- joystick_instance_id = SDL_JoystickInstanceID(joystick);
149
+ joystick_instance_id = SDL_JoystickInstanceID(SDL_GameControllerGetJoystick(game_controller));
163
150
  if (gamepad_instance_id_is_known(joystick_instance_id)) {
164
- continue;
151
+ return true;
165
152
  }
166
- open_joysticks.emplace_back(
167
- shared_ptr<SDL_Joystick>(joystick, SDL_JoystickClose)
153
+ #if SDL_VERSION_ATLEAST(2, 0, 12)
154
+ SDL_GameControllerSetPlayerIndex(game_controller, gamepad_slot);
155
+ #endif
156
+ open_game_controllers.emplace_back(
157
+ shared_ptr<SDL_GameController>(game_controller, SDL_GameControllerClose)
168
158
  );
169
159
  }
170
-
171
- // Reserve gamepad slot and issue gamepad connection event
172
- if (gamepad_slot >= 0 && joystick_instance_id >= 0) {
173
- gamepad_slots[gamepad_slot] = joystick_instance_id;
174
- enqueue_gamepad_connection_event(gamepad_slot, true, -1);
160
+ }
161
+ // ...but fall back on the good, old SDL_Joystick API.
162
+ else if (SDL_Joystick* joystick = SDL_JoystickOpen(i)) {
163
+ gamepad_slot = available_gamepad_slot_index();
164
+ joystick_instance_id = SDL_JoystickInstanceID(joystick);
165
+ if (gamepad_instance_id_is_known(joystick_instance_id)) {
166
+ return true;
175
167
  }
168
+ #if SDL_VERSION_ATLEAST(2, 0, 12)
169
+ SDL_JoystickSetPlayerIndex(joystick, gamepad_slot);
170
+ #endif
171
+ open_joysticks.emplace_back(
172
+ shared_ptr<SDL_Joystick>(joystick, SDL_JoystickClose)
173
+ );
174
+ }
175
+
176
+ // Reserve gamepad slot and issue gamepad connection event
177
+ if (gamepad_slot >= 0 && joystick_instance_id >= 0) {
178
+ gamepad_slots[gamepad_slot] = joystick_instance_id;
179
+ enqueue_gamepad_connection_event(gamepad_slot, true, -1);
176
180
  }
177
181
  break;
178
182
  }