diff options
| author | John Hurst <jhurst@cinecert.com> | 2020-09-08 15:59:02 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-09-08 15:59:02 -0700 |
| commit | a7d9a11e32d22b1d39baee42392df5551e99681b (patch) | |
| tree | 066e607e211b480d644f66dbd2c63da35bb24f6c /src/h__Writer.cpp | |
| parent | 359f824301003a0654cee3168f42686113eed7d1 (diff) | |
| parent | 6e29e26ec330243e7cd9c31317110153d22369ea (diff) | |
Merge pull request #55 from DolbyLaboratories/dolby/fix_invalid_use_of_stack_buffer
Fix read of stack buffer after it went out of scope
Diffstat (limited to 'src/h__Writer.cpp')
| -rwxr-xr-x | src/h__Writer.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/h__Writer.cpp b/src/h__Writer.cpp index fc7f060..0c56b4c 100755 --- a/src/h__Writer.cpp +++ b/src/h__Writer.cpp @@ -374,6 +374,15 @@ ASDCP::Write_EKLV_Packet(Kumu::FileWriter& File, const ASDCP::Dictionary& Dict, byte_t overhead[128]; Kumu::MemIOWriter Overhead(overhead, 128); + // We declare HMACOverhead and its buffer in the outer scope, even though it is not used on + // unencrypted content: the reason is that File.Writev(const byte_t* buf, ui32_t buf_len) doesn't + // write data right away but saves a pointer on the buffer. And we write all the buffers at the end + // when calling File.writev(). + // Declaring the buffer variable in an inner scope means the buffer will go out of scope + // before the data it contains has been actually written, which means its content could be + // overwritten/get corrupted. + byte_t hmoverhead[512]; + Kumu::MemIOWriter HMACOverhead(hmoverhead, 512); if ( FrameBuf.Size() == 0 ) { @@ -455,9 +464,6 @@ ASDCP::Write_EKLV_Packet(Kumu::FileWriter& File, const ASDCP::Dictionary& Dict, { StreamOffset += CtFrameBuf.Size(); - byte_t hmoverhead[512]; - Kumu::MemIOWriter HMACOverhead(hmoverhead, 512); - // write the HMAC if ( Info.UsesHMAC ) { |
