|
165 | 165 | void
|
166 | 166 | vips__new_output_message( j_common_ptr cinfo )
|
167 | 167 | {
|
168 |
| - char buffer[JMSG_LENGTH_MAX]; |
| 168 | + /* Some DoS attacks use jpg files with thousands of warnings. Try to |
| 169 | + * limit the effect these have. |
| 170 | + */ |
| 171 | + if( cinfo->err->num_warnings >= 20 ) { |
| 172 | + if( cinfo->err->num_warnings == 20 ) { |
| 173 | + vips_error( "VipsJpeg", |
| 174 | + "%s", _( "too many warnings" ) ); |
| 175 | + } |
| 176 | + |
| 177 | + jpeg_abort( cinfo ); |
| 178 | + } |
| 179 | + else { |
| 180 | + char buffer[JMSG_LENGTH_MAX]; |
169 | 181 |
|
170 |
| - (*cinfo->err->format_message)( cinfo, buffer ); |
171 |
| - vips_error( "VipsJpeg", _( "%s" ), buffer ); |
| 182 | + (*cinfo->err->format_message)( cinfo, buffer ); |
| 183 | + vips_error( "VipsJpeg", _( "%s" ), buffer ); |
172 | 184 |
|
173 | 185 | #ifdef DEBUG
|
174 |
| - printf( "vips__new_output_message: \"%s\"\n", buffer ); |
| 186 | + printf( "vips__new_output_message: \"%s\"\n", buffer ); |
175 | 187 | #endif /*DEBUG*/
|
176 | 188 |
|
177 |
| - /* This is run for things like file truncated. Signal invalidate to |
178 |
| - * force this op out of cache. |
179 |
| - */ |
180 |
| - if( cinfo->client_data ) |
181 |
| - vips_foreign_load_invalidate( VIPS_IMAGE( cinfo->client_data ) ); |
| 189 | + /* This is run for things like file truncated. Signal |
| 190 | + * invalidate to force this op out of cache. |
| 191 | + */ |
| 192 | + if( cinfo->client_data ) |
| 193 | + vips_foreign_load_invalidate( |
| 194 | + VIPS_IMAGE( cinfo->client_data ) ); |
| 195 | + } |
182 | 196 | }
|
183 | 197 |
|
184 | 198 | /* New error_exit handler.
|
|
0 commit comments