Fix potential unsafe access to VCMTimestampMap::data

The access to |_timestampMap| was guarded by a lock but
not the access to the data pointer stored in |_timestampMap|.
There was a potential race condition if new data was added
in VCMGenericDecoder::Decode() while the data pointer
retrieved from _timestampMap.Pop() was being used in
VCMDecodedFrameCallback::Decoded().

This CL moves the storage of data to within |_timestampMap|,
instead of being a pointer so that it's guarded by the same
lock.

Bug: webrtc:11229
Change-Id: I3f2afb568ed724db5719d508a73de402c4531dec
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/209361
Commit-Queue: Johannes Kron <kron@webrtc.org>
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33374}
This commit is contained in:
Johannes Kron
2021-03-03 14:39:44 +01:00
committed by Commit Bot
parent 752cbaba90
commit b6b782da68
5 changed files with 44 additions and 41 deletions

View File

@ -29,18 +29,6 @@ class VCMReceiveCallback;
enum { kDecoderFrameMemoryLength = 10 };
struct VCMFrameInformation {
int64_t renderTimeMs;
absl::optional<Timestamp> decodeStart;
void* userData;
VideoRotation rotation;
VideoContentType content_type;
EncodedImage::Timing timing;
int64_t ntp_time_ms;
RtpPacketInfos packet_infos;
// ColorSpace is not stored here, as it might be modified by decoders.
};
class VCMDecodedFrameCallback : public DecodedImageCallback {
public:
VCMDecodedFrameCallback(VCMTiming* timing, Clock* clock);
@ -56,7 +44,7 @@ class VCMDecodedFrameCallback : public DecodedImageCallback {
void OnDecoderImplementationName(const char* implementation_name);
void Map(uint32_t timestamp, VCMFrameInformation* frameInfo);
void Map(uint32_t timestamp, const VCMFrameInformation& frameInfo);
int32_t Pop(uint32_t timestamp);
private:
@ -117,7 +105,6 @@ class VCMGenericDecoder {
private:
VCMDecodedFrameCallback* _callback;
VCMFrameInformation _frameInfos[kDecoderFrameMemoryLength];
uint32_t _nextFrameInfoIdx;
std::unique_ptr<VideoDecoder> decoder_;
VideoCodecType _codecType;
const bool _isExternal;