mirror of
				https://github.com/webmproject/libwebp.git
				synced 2025-10-31 10:25:46 +01:00 
			
		
		
		
	anim_encode: Fix encoded_frames_[] overflow
Check encoded_frames_ count and call FlushFrames if necessary after IncreasePreviousDuration. Avoids an overflow in encoded_frames_[] with -kmax 0 and an assertion failure related to the previous and keyframe durations when a frame is forced in this way. Based on patch by tomwei7g <at> gmail Bug: webp:518 Change-Id: Idef685e6c06a67d48fcdc048265ca0e672a01263
This commit is contained in:
		| @@ -946,7 +946,8 @@ static int IncreasePreviousDuration(WebPAnimEncoder* const enc, int duration) { | |||||||
|   int new_duration; |   int new_duration; | ||||||
|  |  | ||||||
|   assert(enc->count_ >= 1); |   assert(enc->count_ >= 1); | ||||||
|   assert(prev_enc_frame->sub_frame_.duration == |   assert(!prev_enc_frame->is_key_frame_ || | ||||||
|  |          prev_enc_frame->sub_frame_.duration == | ||||||
|          prev_enc_frame->key_frame_.duration); |          prev_enc_frame->key_frame_.duration); | ||||||
|   assert(prev_enc_frame->sub_frame_.duration == |   assert(prev_enc_frame->sub_frame_.duration == | ||||||
|          (prev_enc_frame->sub_frame_.duration & (MAX_DURATION - 1))); |          (prev_enc_frame->sub_frame_.duration & (MAX_DURATION - 1))); | ||||||
| @@ -1355,6 +1356,12 @@ int WebPAnimEncoderAdd(WebPAnimEncoder* enc, WebPPicture* frame, int timestamp, | |||||||
|     if (!IncreasePreviousDuration(enc, (int)prev_frame_duration)) { |     if (!IncreasePreviousDuration(enc, (int)prev_frame_duration)) { | ||||||
|       return 0; |       return 0; | ||||||
|     } |     } | ||||||
|  |     // IncreasePreviousDuration() may add a frame to avoid exceeding | ||||||
|  |     // MAX_DURATION which could cause CacheFrame() to over read encoded_frames_ | ||||||
|  |     // before the next flush. | ||||||
|  |     if (enc->count_ == enc->size_ && !FlushFrames(enc)) { | ||||||
|  |       return 0; | ||||||
|  |     } | ||||||
|   } else { |   } else { | ||||||
|     enc->first_timestamp_ = timestamp; |     enc->first_timestamp_ = timestamp; | ||||||
|   } |   } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user