| 215 | } |
| 216 | |
| 217 | int ff_combine_frame(ParseContext *pc, int next, |
| 218 | const uint8_t **buf, int *buf_size) |
| 219 | { |
| 220 | if (pc->overread) { |
| 221 | ff_dlog(NULL, "overread %d, state:%"PRIX32" next:%d index:%d o_index:%d\n", |
| 222 | pc->overread, pc->state, next, pc->index, pc->overread_index); |
| 223 | ff_dlog(NULL, "%X %X %X %X\n", |
| 224 | (*buf)[0], (*buf)[1], (*buf)[2], (*buf)[3]); |
| 225 | } |
| 226 | |
| 227 | /* Copy overread bytes from last frame into buffer. */ |
| 228 | for (; pc->overread > 0; pc->overread--) |
| 229 | pc->buffer[pc->index++] = pc->buffer[pc->overread_index++]; |
| 230 | |
| 231 | if (next > *buf_size) |
| 232 | return AVERROR(EINVAL); |
| 233 | |
| 234 | /* flush remaining if EOF */ |
| 235 | if (!*buf_size && next == END_NOT_FOUND) |
| 236 | next = 0; |
| 237 | |
| 238 | pc->last_index = pc->index; |
| 239 | |
| 240 | /* copy into buffer end return */ |
| 241 | if (next == END_NOT_FOUND) { |
| 242 | void *new_buffer = av_fast_realloc(pc->buffer, &pc->buffer_size, |
| 243 | *buf_size + pc->index + |
| 244 | AV_INPUT_BUFFER_PADDING_SIZE); |
| 245 | |
| 246 | if (!new_buffer) { |
| 247 | av_log(NULL, AV_LOG_ERROR, "Failed to reallocate parser buffer to %d\n", *buf_size + pc->index + AV_INPUT_BUFFER_PADDING_SIZE); |
| 248 | pc->index = 0; |
| 249 | return AVERROR(ENOMEM); |
| 250 | } |
| 251 | pc->buffer = new_buffer; |
| 252 | memcpy(&pc->buffer[pc->index], *buf, *buf_size); |
| 253 | memset(&pc->buffer[pc->index + *buf_size], 0, AV_INPUT_BUFFER_PADDING_SIZE); |
| 254 | pc->index += *buf_size; |
| 255 | return -1; |
| 256 | } |
| 257 | |
| 258 | av_assert0(next >= 0 || pc->buffer); |
| 259 | |
| 260 | *buf_size = |
| 261 | pc->overread_index = pc->index + next; |
| 262 | |
| 263 | /* append to buffer */ |
| 264 | if (pc->index) { |
| 265 | void *new_buffer = av_fast_realloc(pc->buffer, &pc->buffer_size, |
| 266 | next + pc->index + |
| 267 | AV_INPUT_BUFFER_PADDING_SIZE); |
| 268 | if (!new_buffer) { |
| 269 | av_log(NULL, AV_LOG_ERROR, "Failed to reallocate parser buffer to %d\n", next + pc->index + AV_INPUT_BUFFER_PADDING_SIZE); |
| 270 | *buf_size = |
| 271 | pc->overread_index = |
| 272 | pc->index = 0; |
| 273 | return AVERROR(ENOMEM); |
| 274 | } |
no test coverage detected