Skip to content

Commit

Permalink
Only call on_prelude() when prelude passed crc check and limitation c… (
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Tang authored and ColdenCullen committed Oct 9, 2019
1 parent 0d1e206 commit 32713d3
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions source/event_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -1154,8 +1154,6 @@ static int s_verify_prelude_state(
decoder->prelude.prelude_crc = aws_read_u32(decoder->working_buffer + PRELUDE_CRC_OFFSET);
decoder->prelude.total_len = aws_read_u32(decoder->working_buffer + TOTAL_LEN_OFFSET);

decoder->on_prelude(decoder, &decoder->prelude, decoder->user_context);

decoder->running_crc = aws_checksums_crc32(decoder->working_buffer, PRELUDE_CRC_OFFSET, 0);

if (AWS_LIKELY(decoder->running_crc == decoder->prelude.prelude_crc)) {
Expand All @@ -1174,6 +1172,10 @@ static int s_verify_prelude_state(
return AWS_OP_ERR;
}

/* Should only call on_prelude() after passing crc check and limitation check, otherwise call on_prelude() with
* incorrect prelude is error prune. */
decoder->on_prelude(decoder, &decoder->prelude, decoder->user_context);

decoder->running_crc = aws_checksums_crc32(
decoder->working_buffer + PRELUDE_CRC_OFFSET,
(int)sizeof(decoder->prelude.prelude_crc),
Expand Down

0 comments on commit 32713d3

Please sign in to comment.