Blame SOURCES/flac-1.3.0-cve-2014-9028.patch

670658
Merged four commits:
670658
670658
commit fcf0ba06ae12ccd7c67cee3c8d948df15f946b85
670658
Author: Erik de Castro Lopo <erikd@mega-nerd.com>
670658
Date:   Wed Nov 19 19:35:59 2014 -0800
670658
670658
    src/libFACL/stream_decoder.c : Fail safely to avoid a heap overflow.
670658
    
670658
    A file provided by the reporters caused the stream decoder to write to
670658
    un-allocated heap space resulting in a segfault. The solution is to
670658
    error out (by returning false from read_residual_partitioned_rice_())
670658
    instead of trying to continue to decode.
670658
    
670658
    Fixes: CVE-2014-9028
670658
    Reported-by: Michele Spagnuolo,
670658
                 Google Security Team <mikispag@google.com>
670658
670658
commit 5a365996d739bdf4711af51d9c2c71c8a5e14660
670658
Author: Erik de Castro Lopo <erikd@mega-nerd.com>
670658
Date:   Thu Nov 27 11:55:11 2014 +1100
670658
670658
    src/libFLAC/stream_decoder.c : Fail safely to avoid a heap overflow.
670658
    
670658
    This fix is closely related to the fix for CVE-2014-9028. When that
670658
    fix went public Miroslav Lichvar noticed a similar potential problem
670658
    spot in the same function and was able to craft a file to trigger a
670658
    heap write overflow.
670658
    
670658
    Reported-by : Miroslav Lichvar <mlichvar@redhat.com>
670658
670658
commit b4b2910bdca010808ccf2799f55562fa91f4347b
670658
Author: Erik de Castro Lopo <erikd@mega-nerd.com>
670658
Date:   Wed Dec 10 18:54:16 2014 +1100
670658
670658
    src/libFLAC/stream_decoder.c : Fix seek bug.
670658
    
670658
    Janne Hyvärinen reported a problem with seeking as a result of the
670658
    fix for CVE-2014-9028. This is a different solution to the issue
670658
    that should not adversely affect seeking.
670658
    
670658
    This version of the fix for the above CVE has been extensively fuzz
670658
    tested using afl (http://lcamtuf.coredump.cx/afl/).
670658
    
670658
    Reported-by: Janne Hyvärinen <cse@sci.fi>
670658
670658
commit fed0dfa1086296df0af41ca8f0c6430d5ac75c87
670658
Author: Miroslav Lichvar <mlichvar@redhat.com>
670658
Date:   Mon Dec 15 15:46:12 2014 +0100
670658
670658
    src/libFLAC/stream_decoder.c : Rework fix for seeking bug.
670658
    
670658
    To avoid crash caused by an unbound LPC decoding when predictor order is
670658
    larger than blocksize, the sanity check needs to be moved to the subframe
670658
    decoding functions.
670658
    
670658
    Signed-off-by: Erik de Castro Lopo <erikd@mega-nerd.com>
670658
670658
diff -up flac-1.3.0/src/libFLAC/stream_decoder.c.cve-2014-9028 flac-1.3.0/src/libFLAC/stream_decoder.c
670658
--- flac-1.3.0/src/libFLAC/stream_decoder.c.cve-2014-9028	2015-03-27 16:59:10.898884915 +0100
670658
+++ flac-1.3.0/src/libFLAC/stream_decoder.c	2015-03-27 17:00:34.879125031 +0100
670658
@@ -2550,6 +2550,11 @@ FLAC__bool read_subframe_fixed_(FLAC__St
670658
 		case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
670658
 			if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
670658
 				return false; /* read_callback_ sets the state for us */
670658
+			if(decoder->private_->frame.header.blocksize >> u32 < order) {
670658
+				send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
670658
+				decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
670658
+				return true;
670658
+			}
670658
 			subframe->entropy_coding_method.data.partitioned_rice.order = u32;
670658
 			subframe->entropy_coding_method.data.partitioned_rice.contents = &decoder->private_->partitioned_rice_contents[channel];
670658
 			break;
670658
@@ -2629,6 +2634,11 @@ FLAC__bool read_subframe_lpc_(FLAC__Stre
670658
 		case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
670658
 			if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
670658
 				return false; /* read_callback_ sets the state for us */
670658
+			if(decoder->private_->frame.header.blocksize >> u32 < order) {
670658
+				send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
670658
+				decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
670658
+				return true;
670658
+			}
670658
 			subframe->entropy_coding_method.data.partitioned_rice.order = u32;
670658
 			subframe->entropy_coding_method.data.partitioned_rice.contents = &decoder->private_->partitioned_rice_contents[channel];
670658
 			break;
670658
@@ -2704,21 +2714,8 @@ FLAC__bool read_residual_partitioned_ric
670658
 	const unsigned plen = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
670658
 	const unsigned pesc = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
670658
 
670658
-	/* sanity checks */
670658
-	if(partition_order == 0) {
670658
-		if(decoder->private_->frame.header.blocksize < predictor_order) {
670658
-			send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
670658
-			decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
670658
-			return true;
670658
-		}
670658
-	}
670658
-	else {
670658
-		if(partition_samples < predictor_order) {
670658
-			send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
670658
-			decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
670658
-			return true;
670658
-		}
670658
-	}
670658
+	/* invalid predictor and partition orders mush be handled in the callers */
670658
+	FLAC__ASSERT(partition_order > 0? partition_samples >= predictor_order : decoder->private_->frame.header.blocksize >= predictor_order);
670658
 
670658
 	if(!FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(partitioned_rice_contents, flac_max(6u, partition_order))) {
670658
 		decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;