avformat/oggdec: Factor buffer reallocation out
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
This commit is contained in:
		
							parent
							
								
									3c740f2d9f
								
							
						
					
					
						commit
						5d5b0bbcb7
					
				| @ -297,6 +297,20 @@ static int data_packets_seen(const struct ogg *ogg) | |||||||
|     return 0; |     return 0; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | static int buf_realloc(struct ogg_stream *os, int size) | ||||||
|  | { | ||||||
|  |     /* Even if invalid guarantee there's enough memory to read the page */ | ||||||
|  |     if (os->bufsize - os->bufpos < size) { | ||||||
|  |         uint8_t *nb = av_realloc(os->buf, 2*os->bufsize + AV_INPUT_BUFFER_PADDING_SIZE); | ||||||
|  |         if (!nb) | ||||||
|  |             return AVERROR(ENOMEM); | ||||||
|  |         os->buf = nb; | ||||||
|  |         os->bufsize *= 2; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     return 0; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| static int ogg_read_page(AVFormatContext *s, int *sid, int probing) | static int ogg_read_page(AVFormatContext *s, int *sid, int probing) | ||||||
| { | { | ||||||
|     AVIOContext *bc = s->pb; |     AVIOContext *bc = s->pb; | ||||||
| @ -378,14 +392,9 @@ static int ogg_read_page(AVFormatContext *s, int *sid, int probing) | |||||||
|     if (idx >= 0) { |     if (idx >= 0) { | ||||||
|         os = ogg->streams + idx; |         os = ogg->streams + idx; | ||||||
| 
 | 
 | ||||||
|         /* Even if invalid guarantee there's enough memory to read the page */ |         ret = buf_realloc(os, size); | ||||||
|         if (os->bufsize - os->bufpos < size) { |         if (ret < 0) | ||||||
|             uint8_t *nb = av_realloc(os->buf, 2*os->bufsize + AV_INPUT_BUFFER_PADDING_SIZE); |             return ret; | ||||||
|             if (!nb) |  | ||||||
|                 return AVERROR(ENOMEM); |  | ||||||
|             os->buf = nb; |  | ||||||
|             os->bufsize *= 2; |  | ||||||
|         } |  | ||||||
| 
 | 
 | ||||||
|         readout_buf = os->buf + os->bufpos; |         readout_buf = os->buf + os->bufpos; | ||||||
|     } else { |     } else { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user