LMMS / LMMS/lmms

Lv2 MDA Piano causes an invalid write

Open
#5,903 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
C++
Stars
10.4k
Forks
1.3k
Avg merge
2d 13h
Merged PRs (30d)
7

Description

### Bug Summary

Lv2 MDA Piano causes an invalid write when notes are edited while played.

#### Steps to reproduce

Use Lv2 MDA Piano. Edit notes (volume) while playing them (start and stop a few times). Possibly it's not even required to edit notes.

#### Expected behavior

No invalid write.

#### Actual behavior

Invalid write.

#### Affected LMMS versions

Any.

#### Logs

Click to expand
Using vgdb (http://log.fundamental-code.com/2012/01/30/vgdb-uniting-valgrind-and-gdb.html),
valgrind notices the first invalid write inside mdaPiano, where is written directly behind the
output buffer.

$ cat -n src/mdaPiano.cpp | grep -C 5 381

376 }
377 comb[cpos] = l + r;
378 ++cpos &= cmax;
379 x = cdep * comb[cpos]; //stereo simulator
380
381 *out0++ = l + x;
382 *out1++ = r - x;
383 }
384
385 if(!end)
386 {

valgrind:
==811656== Thread 10 Mixer::fifoWrite:

==811656== Invalid write of size 4
==811656== at 0x1389C637: mdaPiano::processReplacing(float**, float**, int) (mdaPiano.cpp:381)
==811656== by 0x1389DDF2: lvz_run (wrapper.cpp:166)
==811656== by 0x3D7100: lilv_instance_run (lilv.h:1948)
==811656== by 0x3D848E: Lv2Proc::run(short) (Lv2Proc.cpp:333)
==811656== by 0x3CE9CC: Lv2ControlBase::run(short) (Lv2ControlBase.cpp:148)
==811656== by 0x20B7C230: Lv2Instrument::play(std::array*) (Lv2Instrument.cpp:165)
==811656== by 0x35F2CA: InstrumentPlayHandle::play(std::array*) (InstrumentPlayHandle.h:65)
==811656== by 0x38BFD2: PlayHandle::doProcessing() (PlayHandle.cpp:58)
==811656== by 0x35F0B0: ThreadableJob::process() (ThreadableJob.h:74)
==811656== by 0x37D53C: MixerWorkerThread::JobQueue::run() (MixerWorkerThread.cpp:84)
==811656== by 0x37D7A8: MixerWorkerThread::startAndWaitForJobs() (MixerWorkerThread.cpp:157)
==811656== by 0x376266: Mixer::renderNextBuffer() (Mixer.cpp:389)
==811656== Address 0x18299790 is 0 bytes after a block of size 1,024 alloc'd
==811656== at 0x483ADEF: operator new(unsigned long) (vg_replace_malloc.c:342)
==811656== by 0x3B8B5D: __gnu_cxx::new_allocator::allocate(unsigned long, void const*) (new_allocator.h:115)
==811656== by 0x3B8AB1: std::allocator_traits >::allocate(std::allocator&, unsigned long) (alloc_traits.h:460)
==811656== by 0x3B89FF: std::_Vector_base >::_M_allocate(unsigned long) (stl_vector.h:346)
==811656== by 0x3B8906: std::_Vector_base >::_M_create_storage(unsigned long) (stl_vector.h:361)
==811656== by 0x3B8722: std::_Vector_base >::_Vector_base(unsigned long, std::allocator const&) (stl_vector.h:305)
==811656== by 0x3B8592: std::vector >::vector(unsigned long, std::allocator const&) (stl_vector.h:511)
==811656== by 0x3D558B: Lv2Ports::Audio::Audio(unsigned long, bool) (Lv2Ports.cpp:305)
==811656== by 0x3D943D: Lv2Proc::createPort(unsigned long) (Lv2Proc.cpp:585)
==811656== by 0x3D9D16: Lv2Proc::createPorts() (Lv2Proc.cpp:723)
==811656== by 0x3D8829: Lv2Proc::initPlugin() (Lv2Proc.cpp:393)
==811656== by 0x3D7A0D: Lv2Proc::Lv2Proc(LilvPluginImpl const*, Model*) (Lv2Proc.cpp:164)

gdb says:

(gdb) bt

#0 mdaPiano::processReplacing(float**, float**, int) (this=0x18635c20, inputs=0x0, outputs=0xba82810, sampleFrames=256) at ../src/mdaPiano.cpp:381
#1 0x000000001389ddf3 in lvz_run(LV2_Handle, uint32_t) (instance=0x12d5d1c0, sample_count=256) at ../lvz/wrapper.cpp:166
#2 0x00000000003d7101 in lilv_instance_run(LilvInstance*, uint32_t) (instance=0x17a56f90, sample_count=256) at /usr/include/lilv-0/lilv/lilv.h:1948
#3 0x00000000003d848f in Lv2Proc::run(short) (this=0x97dacf0, frames=256) at /home/johannes/cprogs/lmms/master/src/core/lv2/Lv2Proc.cpp:333
#4 0x00000000003ce9cd in Lv2ControlBase::run(short) (this=0x218300e8, frames=256) at /home/johannes/cprogs/lmms/master/src/core/lv2/Lv2ControlBase.cpp:148
#5 0x0000000020b7c231 in Lv2Instrument::play(std::array*) (this=0x21830080, buf=0x21850080) at /home/johannes/cprogs/lmms/master/plugins/Lv2Instrument/Lv2Instru
#6 0x000000000035f2cb in InstrumentPlayHandle::play(std::array*) (this=0x16b166c0, _working_buffer=0x21850080) at /home/johannes/cprogs/lmms/master/include/Inst
#7 0x000000000038bfd3 in PlayHandle::doProcessing() (this=0x16b166c0) at /home/johannes/cprogs/lmms/master/src/core/PlayHandle.cpp:58
#8 0x000000000035f0b1 in ThreadableJob::process() (this=0x16b166c0) at /home/johannes/cprogs/lmms/master/include/ThreadableJob.h:74
#9 0x000000000037d53d in MixerWorkerThread::JobQueue::run() (this=0x707180 ) at /home/johannes/cprogs/lmms/master/src/core/MixerWorkerThr
#10 0x000000000037d7a9 in MixerWorkerThread::startAndWaitForJobs() () at /home/johannes/cprogs/lmms/master/src/core/MixerWorkerThread.cpp:157
#11 0x0000000000376267 in Mixer::renderNextBuffer() (this=0xb8225d0) at /home/johannes/cprogs/lmms/master/src/core/Mixer.cpp:389
#12 0x0000000000378d4f in Mixer::fifoWriter::run() (this=0x97e0bc0) at /home/johannes/cprogs/lmms/master/src/core/Mixer.cpp:1263
#13 0x0000000005f2df0f in () at /usr/lib/libQt5Core.so.5
#14 0x00000000048963e9 in start_thread () at /usr/lib/libpthread.so.0
#15 0x00000000066ac293 in clone () at /usr/lib/libc.so.6
(gdb) info args
this = 0x18635c20
inputs = 0x0
outputs = 0xba82810
sampleFrames = 256
(gdb) info locals
V = 0x18636054
end = true
out0 = 0x18299794
out1 = 0x18299bd0
frame = 256
frames = 101
v = 13
x = -0.0248893611
l = -0.204520881
r = -0.186344534
i = -9666
ev = 0x100b1c6c

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/mdaPiano.cpp around line 381 and reproduce the Lv2 MDA Piano playback/editing sequence under Valgrind. Trace the output buffer allocation in Lv2Ports.cpp and the call path through lvz/wrapper.cpp and src/core/lv2/Lv2Proc.cpp; done means the reproduction no longer reports an invalid write.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
audio-video-rtc
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.