Add a check in the BlockBuffer of AEC2 to guard for buffer overflows.

Ensure that the ring buffer does not return a pointer into the buffer if
no data is available to read.

The ring buffer fix is not directly applicable to issue webrtc:7845, but may cause related memory errors.

BUG=webrtc:7845

Review-Url: https://codereview.webrtc.org/2971313002
Cr-Commit-Position: refs/heads/master@{#18940}
diff --git a/webrtc/common_audio/ring_buffer.c b/webrtc/common_audio/ring_buffer.c
index 5fc653b..5a91205 100644
--- a/webrtc/common_audio/ring_buffer.c
+++ b/webrtc/common_audio/ring_buffer.c
@@ -118,7 +118,6 @@
                                                    &buf_ptr_bytes_1,
                                                    &buf_ptr_2,
                                                    &buf_ptr_bytes_2);
-
     if (buf_ptr_bytes_2 > 0) {
       // We have a wrap around when reading the buffer. Copy the buffer data to
       // |data| and point to it.
@@ -131,7 +130,7 @@
     }
     if (data_ptr) {
       // |buf_ptr_1| == |data| in the case of a wrap.
-      *data_ptr = buf_ptr_1;
+      *data_ptr = read_count == 0 ? NULL : buf_ptr_1;
     }
 
     // Update read position