sointu: Sample-based oscillators could hard crash if a x87 stack overflow happened when calculating the current position in the sample

This problem is weird - the musician experienced weird native tracker and plugin hard crashes when editing stacks. I boiled the instrument down to this minimal example:

name: rp-Berlin
numvoices: 7
units:
    - type: oscillator
      id: 2
      parameters: {attack: 64, color: 42, decay: 64, detune: 74, gain: 128, looplength: 563, loopstart: 5448, phase: 0, release: 64, samplestart: 143113, shape: 82, stereo: 1, sustain: 64, transpose: 69, type: 4, unison: 1}
    - type: out
      id: 11
      parameters: {auxgain: 64, color: 64, damp: 0, detune: 64, dry: 128, feedback: 96, gain: 64, notetracking: 2, outgain: 64, phase: 0, pregain: 40, shape: 64, stereo: 1, transpose: 64, type: 0}

When disabling or deleting either of the units, the native tracker (and plugin) hard-crash. I collected debug output as well: sointu_crashlog2.log

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 16 (16 by maintainers)

Commits related to this issue

Most upvoted comments

Woohoo! I can’t reproduce either of the problems on windows with the binaries you linked. Looks fixed!

Ok! I think I got it!

The sample-based oscillators converted samplepos, the position in the sample, to an integer and did samplepos < loop_end comparison to check if we are past looping. Unfortunately, the < comparison was done in signed math, using jl instruction. Normally, samplepos should be always a non-negative integer. But if the x87 FPU stack overflowed exactly at right position, we then got 0x80000000 in samplepos (“the integer indefinite value” according to x87 spec), which is equal to -2147483648. Thus, because of the signed comparison, we considered that sample is not looping and read the sample table at position -2147483648, well out of bounds.

Changing jl to jb makes sure we always wrap to within sample table, no matter what.

Can you try if the binaries in https://github.com/vsariola/sointu/actions/runs/10972368119 fix your issue?

Am able to reproduce; debugging the CGO calls is a pain so could not figure out what exactly is causing the crash yet. Just don’t do it for now 😉