Closed Bug 1137169 Opened 9 years ago Closed 8 years ago

Uninitialised value uses related to mozilla::dom::WebAudioUtils::SpeexResamplerProcess

Categories

(Core :: WebRTC: Audio/Video, defect, P3)

x86_64
Linux
defect

Tracking

()

RESOLVED FIXED
mozilla42
Tracking Status
firefox42 --- fixed

People

(Reporter: jseward, Assigned: padenot)

References

(Depends on 1 open bug)

Details

Attachments

(2 files, 1 obsolete file)

Mochitest/Valgrind run, seen in

dom/media/tests/mochitest/test_peerConnection_noTrickleAnswer.html
Component: Web Audio → WebRTC: Audio/Video
Assignee: nobody → padenot
Attached patch A possible fix (obsolete) — Splinter Review
This stops Valgrind complaining, although it's something of a
blunt-instrument solution.
Attachment #8575432 - Flags: feedback?(padenot)
Comment on attachment 8575432 [details] [diff] [review]
A possible fix

Review of attachment 8575432 [details] [diff] [review]:
-----------------------------------------------------------------

Randell, does that make sense to you ? I'm afraid that it's too far from the MSG for me to know what to do here.
Attachment #8575432 - Flags: feedback?(padenot) → feedback?(rjesup)
rjesup, ping?
backlog: --- → webRTC+
Rank: 38
Priority: -- → P3
I've looked at this some.   I'm not sure how uninitialized gets to be flagged here... And I really don't want to spend the cycles to just quiet valgrind.  I'll check if I had a possible patch for it (not on that machine ATM).
(In reply to Maire Reavy [:mreavy] (Plz needinfo me) from comment #4)
> I've looked at this some.   I'm not sure how uninitialized gets to be
> flagged here... And I really don't want to spend the cycles to just quiet
> valgrind.  I'll check if I had a possible patch for it (not on that machine
> ATM).

FWIW, Valgrind is usually right about these things.
I looked at 

int
WebAudioUtils::SpeexResamplerProcess(SpeexResamplerState* aResampler,
                                     uint32_t aChannel,
                                     const int16_t* aIn, uint32_t* aInLen,
                                     int16_t* aOut, uint32_t* aOutLen)

at dom/media/webaudio/WebAudioUtils.cpp:88.  Almost all of the time,
*aInLen == *aOutLen == 441.  But for 4 out of at least several hundred
cases, those two have the value 882 instead, and it is exactly for these
4 that Valgrind complains.

I notice that the two arrays tmp1 and tmp2 are given initial sizes
of 512 (that is, WEBAUDIO_BLOCK_SIZE * 4), which is > 441, in which
cases Valgrind does not complain, and < 882, for which it does 
complain.  So I wonder if that is somehow relevant?  But the two
arrays are resized to the actual required size before use, so at
least in this function I don't see anything obviously wrong.
Thanks to Randell for helping me make sense of this.

This is caused by a confusion about number-of-bytes vs number-of-samples
in the error case in MediaPipelineReceiveAudio::PipelineListener::NotifyPull.

If the call to GetAudioFrame fails, then err will be != kMediaConduitNoError
and specifically will be kMediaConduitSessionNotInited.  It then enters
here

    if (err != kMediaConduitNoError) {
      // Insert silence on conduit/GIPS failure (extremely unlikely)

and computes into samples_length, the number of bytes of samples_data
that need to be zeroed out.  But further down, samples_length is handed
to segment.AppendFrames(..) to mean the number of samples to add.  The
effect is that subsequent processing overruns the zeroed out area
because the size of a sample is 16 bits.
Attached patch A better fixSplinter Review
Attachment #8575432 - Attachment is obsolete: true
Attachment #8575432 - Flags: feedback?(rjesup)
Attachment #8630182 - Flags: review?(rjesup)
Attachment #8630182 - Flags: review?(rjesup) → review+
https://hg.mozilla.org/mozilla-central/rev/14c4e4aded9f
Status: NEW → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla42
Depends on: 1190095
You need to log in before you can comment on or make changes to this bug.