Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resample segmentation fault for rate::AbstractFloat #262

Closed
1oly opened this issue Mar 13, 2019 · 5 comments
Closed

Resample segmentation fault for rate::AbstractFloat #262

1oly opened this issue Mar 13, 2019 · 5 comments
Labels

Comments

@1oly
Copy link
Contributor

1oly commented Mar 13, 2019

Hello,

I'm getting a segmentation fault for resample when rate is a certain float value (example coming from an actual script where s and y are audio signals):

using DSP
s = rand(1920000);
y = rand(2629632);
rate = length(s)/length(y)
X = resample(y,rate)

by using Rational type, I don't see a segmentation fault:

using DSP
s = rand(1920000);
y = rand(2629632);
rate = length(s)//length(y) # Rational here
X = resample(y,rate)

I tried to look in resample_filter

function resample_filter(rate::AbstractFloat, Nϕ = 32, rel_bw = 1.0, attenuation = 60)

but cannot reproduce manually.

Will be happy to help out if this is not an issue on my side.

Thanks!

Error:

signal (11): Segmentation fault: 11
in expression starting at no file:0
setindex! at ./array.jl:767 [inlined]
filt! at /Users/oliver/.julia/packages/DSP/efNaR/src/Filters/stream_filt.jl:635
filt at /Users/oliver/.julia/packages/DSP/efNaR/src/Filters/stream_filt.jl:648
resample at /Users/oliver/.julia/packages/DSP/efNaR/src/Filters/stream_filt.jl:703
resample at /Users/oliver/.julia/packages/DSP/efNaR/src/Filters/stream_filt.jl:708
unknown function (ip: 0x11f37f318)
jl_fptr_trampoline at /Users/osx/buildbot/slave/package_osx64/build/src/gf.c:1864
do_call at /Users/osx/buildbot/slave/package_osx64/build/src/interpreter.c:323
eval_stmt_value at /Users/osx/buildbot/slave/package_osx64/build/src/interpreter.c:362 [inlined]
eval_body at /Users/osx/buildbot/slave/package_osx64/build/src/interpreter.c:759
jl_interpret_toplevel_thunk_callback at /Users/osx/buildbot/slave/package_osx64/build/src/interpreter.c:885
unknown function (ip: 0xfffffffffffffffe)
unknown function (ip: 0x10e2c7caf)
unknown function (ip: 0xffffffffffffffff)
jl_interpret_toplevel_thunk at /Users/osx/buildbot/slave/package_osx64/build/src/interpreter.c:894
jl_toplevel_eval_flex at /Users/osx/buildbot/slave/package_osx64/build/src/toplevel.c:764
jl_toplevel_eval at /Users/osx/buildbot/slave/package_osx64/build/src/toplevel.c:773 [inlined]
jl_toplevel_eval_in at /Users/osx/buildbot/slave/package_osx64/build/src/toplevel.c:793
eval at ./boot.jl:328
eval_user_input at /Users/osx/buildbot/slave/package_osx64/build/usr/share/julia/stdlib/v1.1/REPL/src/REPL.jl:85
macro expansion at /Users/osx/buildbot/slave/package_osx64/build/usr/share/julia/stdlib/v1.1/REPL/src/REPL.jl:117 [inlined]
#26 at ./task.jl:259
jl_apply at /Users/osx/buildbot/slave/package_osx64/build/src/./julia.h:1571 [inlined]
start_task at /Users/osx/buildbot/slave/package_osx64/build/src/task.c:572
Allocations: 5752859 (Pool: 5751833; Big: 1026); GC: 14
Segmentation fault: 11

and versioninfo:

Julia Version 1.1.0
Commit 80516ca202 (2019-01-21 21:24 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin14.5.0)
  CPU: Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.1 (ORCJIT, skylake)

and Pkg.status:

  [537997a7] AbstractPlotting v0.9.6 #master (https://github.com/JuliaPlots/AbstractPlotting.jl.git)
  [03ede2b8] AeroAcoustics v0.0.4 [`../../dev/AeroAcoustics`]
  [c7e460c6] ArgParse v0.6.2
  [c52e3926] Atom v0.7.15
  [6e4b80f9] BenchmarkTools v0.4.2
  [b99e7846] BinaryProvider v0.5.3
  [5ae59095] Colors v0.9.5
  [717857b8] DSP v0.5.2
  [a93c6f00] DataFrames v0.17.1
  [b4f34e82] Distances v0.8.0
  [e30172f5] Documenter v0.21.5
  [8f5d6c58] EzXML v0.9.1
  [7a1cc6ca] FFTW v0.2.4
  [add2ef01] GDAL v0.2.0
  [e9467ef8] GLMakie v0.0.5 #master (https://github.com/JuliaPlots/GLMakie.jl.git)
  [28b8d3ca] GR v0.38.1+ #master (https://github.com/jheinen/GR.jl.git)
  [f67ccb44] HDF5 v0.11.0
  [7073ff75] IJulia v1.17.0
  [86fae568] ImageView v0.8.2
  [c601a237] Interact v0.9.1
  [42fd0dbc] IterativeSolvers v0.8.1
  [aa1ae85d] JuliaInterpreter v0.1.1 #master (https://github.com/JuliaDebug/JuliaInterpreter.jl)
  [e5e0dc1b] Juno v0.5.5
  [b964fa9f] LaTeXStrings v1.0.3
  [4345ca2d] Loess v0.5.0
  [ee78f7c6] Makie v0.9.3 #master (https://github.com/JuliaPlots/Makie.jl.git)
  [dbd62bd0] MakieGallery v0.0.6
  [4d0d745f] PDFIO v0.1.1
  [8314cec4] PGFPlotsX v0.3.5
  [9b87118b] PackageCompiler v0.6.3+ [`~/.julia/dev/PackageCompiler`]
  [d96e819e] Parameters v0.10.3
  [f0f68f2c] PlotlyJS v0.12.3
  [91a5bcdd] Plots v0.23.1
  [c46f51b8] ProfileView v0.4.0
  [92933f4c] ProgressMeter v0.9.0
  [d330b81b] PyPlot v2.8.0
  [295af30f] Revise v1.1.0
  [90137ffa] StaticArrays v0.10.3
  [a759f4b9] TimerOutputs v0.5.0
  [b8865327] UnicodePlots v1.1.0
  [8149f6b0] WAV v1.0.1
@martinholters
Copy link
Member

The @inbounds here seems fishy:

@inbounds buffer[bufIdx] = yLower + yUpper * kernel.α

Removing it, I get

julia> X = resample(y,rate)
ERROR: BoundsError: attempt to access 1920000-element Array{Float64,1} at index [1920001]
Stacktrace:
 [1] setindex! at ./array.jl:767 [inlined]
 [2] filt!(::Array{Float64,1}, ::FIRFilter{DSP.Filters.FIRArbitrary{Float64}}, ::Array{Float64,1}) at DSP/src/Filters/stream_filt.jl:635
 [3] filt(::FIRFilter{DSP.Filters.FIRArbitrary{Float64}}, ::Array{Float64,1}) at DSP/src/Filters/stream_filt.jl:648
 [4] resample(::Array{Float64,1}, ::Float64, ::Array{Float64,1}) at DSP/src/Filters/stream_filt.jl:703
 [5] resample(::Array{Float64,1}, ::Float64) at DSP/src/Filters/stream_filt.jl:708
 [6] top-level scope at none:0

There's two issues here:

  1. filt! should not assume buffer to be of sufficient size. If we keep the @inbounds, we need to verify before the loop.
  2. In this case, the buffer should have been allocated with (at least) the required size. I'm not quite into the resampling machinery, though, so I don't know where/how to fix this.

@1oly
Copy link
Contributor Author

1oly commented Mar 13, 2019

Thanks for the quick reply and for tracking down the issue to @inbounds. Been looking a bit more and found this line:

# TODO: figure out why this fails. Might be fine, but the filter operation might not being stepping through the phases correcty.
from this commit: 6a4e6d3

Looks like this has been an issue before since tests were disabled and I do get different results for inputlength for Arbitrary or Rational here :

reqInlen = inputlength(self, outLen)

@galenlynch galenlynch added the bug label Mar 14, 2019
galenlynch added a commit to galenlynch/DSP.jl that referenced this issue Apr 9, 2019
A number of exported functions in stream_filt.jl have @inbounds access to
buffers without verifying their lengths. This can cause segfaults, as seen in
issue JuliaDSP#262.
galenlynch added a commit that referenced this issue Apr 11, 2019
* Check buffer lengths in stream filtering functions before access

A number of exported functions in stream_filt.jl have @inbounds access to
buffers without verifying their lengths. This can cause segfaults, as seen in
issue #262.

* Fix buffer length checking

I can't figure out the buffer length requirement for one function, and removed
the `@inbounds` macro until I can.

* Update src/Filters/stream_filt.jl

Co-Authored-By: galenlynch <[email protected]>

* Update src/Filters/stream_filt.jl

Co-Authored-By: galenlynch <[email protected]>

* Fix estimation of buffer length required
@galenlynch
Copy link
Member

@1oly #272 should hopefully fix the segfaults, but not address the underlying problem. However, using master should produce more useful errors. Please let us know if you get any more insight into what is causing these errors.

@1oly
Copy link
Contributor Author

1oly commented Apr 11, 2019

Thanks for addressing the segfault. Will get back if I find the culprit...

@wheeheee
Copy link
Contributor

Closing in favour of #317

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants