bare-jpeg 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/binding.c CHANGED
@@ -73,9 +73,9 @@ bare_jpeg_decode(js_env_t *env, js_callback_info_t *info) {
73
73
 
74
74
  jpeg_start_decompress(&decoder);
75
75
 
76
- int width = decoder.output_width;
77
- int height = decoder.output_height;
78
- int channels = decoder.output_components;
76
+ JDIMENSION width = decoder.output_width;
77
+ JDIMENSION height = decoder.output_height;
78
+ JDIMENSION channels = decoder.output_components;
79
79
 
80
80
  js_value_t *result;
81
81
  err = js_create_object(env, &result);
@@ -94,7 +94,7 @@ bare_jpeg_decode(js_env_t *env, js_callback_info_t *info) {
94
94
  V(height);
95
95
  #undef V
96
96
 
97
- len = width * height * 4;
97
+ len = (size_t) width * height * 4;
98
98
 
99
99
  js_value_t *buffer;
100
100
 
@@ -107,15 +107,15 @@ bare_jpeg_decode(js_env_t *env, js_callback_info_t *info) {
107
107
 
108
108
  JSAMPARRAY scanlines = (*decoder.mem->alloc_sarray)((j_common_ptr) &decoder, JPOOL_IMAGE, width * channels, 1);
109
109
 
110
- int row = 0;
110
+ JDIMENSION row = 0;
111
111
 
112
112
  while (decoder.output_scanline < decoder.output_height) {
113
113
  jpeg_read_scanlines(&decoder, scanlines, 1);
114
114
 
115
115
  const uint8_t *src = scanlines[0];
116
- uint8_t *dst = data + row * width * 4;
116
+ uint8_t *dst = data + (size_t) row * width * 4;
117
117
 
118
- for (int x = 0; x < width; x++) {
118
+ for (JDIMENSION x = 0; x < width; x++) {
119
119
  dst[x * 4 + 0] = src[x * channels + 0];
120
120
  dst[x * 4 + 1] = src[x * channels + 1];
121
121
  dst[x * 4 + 2] = src[x * channels + 2];
@@ -159,6 +159,13 @@ bare_jpeg_encode(js_env_t *env, js_callback_info_t *info) {
159
159
  err = js_get_value_int64(env, argv[3], &quality);
160
160
  assert(err == 0);
161
161
 
162
+ if (width < 0 || width > JPEG_MAX_DIMENSION || height < 0 || height > JPEG_MAX_DIMENSION) {
163
+ err = js_throw_error(env, NULL, "Invalid JPEG dimensions");
164
+ assert(err == 0);
165
+
166
+ return NULL;
167
+ }
168
+
162
169
  bare_jpeg_error_t error;
163
170
 
164
171
  struct jpeg_compress_struct encoder;
@@ -194,12 +201,12 @@ bare_jpeg_encode(js_env_t *env, js_callback_info_t *info) {
194
201
 
195
202
  jpeg_start_compress(&encoder, true);
196
203
 
197
- uint8_t *dst = malloc(width * 3);
204
+ uint8_t *dst = malloc((size_t) width * 3);
198
205
 
199
206
  while (encoder.next_scanline < encoder.image_height) {
200
- const uint8_t *src = data + encoder.next_scanline * width * 4;
207
+ const uint8_t *src = data + (size_t) encoder.next_scanline * width * 4;
201
208
 
202
- for (int x = 0; x < width; x++) {
209
+ for (JDIMENSION x = 0; x < (JDIMENSION) width; x++) {
203
210
  dst[x * 3 + 0] = src[x * 4 + 0];
204
211
  dst[x * 3 + 1] = src[x * 4 + 1];
205
212
  dst[x * 3 + 2] = src[x * 4 + 2];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-jpeg",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "JPEG support for Bare",
5
5
  "exports": {
6
6
  "./package": "./package.json",
Binary file
Binary file
Binary file
Binary file