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

Fix rare out-of-bounds write in FLACCL #353

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ledoge
Copy link

@ledoge ledoge commented Sep 28, 2024

Fixes #315

Note that I have no prior experience with OpenCL and haven't tested this patch extensively, so I'm not fully confident that this doesn't break anything.

@c72578
Copy link
Collaborator

c72578 commented Nov 1, 2024

@ledoge Thanks for your PR.
Here is a build from GitHub Actions, which contains the updated flac.cl:
CUETools_2.2.6_2024-11-01_git_408b68d_Fix_rare_out-of-bounds_write_in_FLACCL.zip
SHA256: b245bffd489cc5f7a21132fc91edb78c8346333a969bd41b61d52bf8a5f22d67

@DarkVoyage, please check.

@DarkVoyage
Copy link

DarkVoyage commented Nov 12, 2024

I use flac.cl a lot, so if I catch any glitches, I will write.
This version fixes the problem with that file.

@DarkVoyage

This comment was marked as off-topic.

@c72578

This comment was marked as off-topic.

@c72578
Copy link
Collaborator

c72578 commented Dec 31, 2024

@agressiv, would you mind testing the build above with e.g. NVIDIA GeForce RTX 4090 using FLACCL?

@agressiv
Copy link

Hi! I looked back through #315 and used the same settings, as well as re-encoding their sample file. I am not getting any errors:

D:\Burn>"C:\Program Files\CUETools_2.2.6\CUETools.FLACCL.cmd.exe" -11 --lax --fast-gpu "09 - Year Of The Cat.wav"
CUETools FLACCL 2.2.6, Copyright (C) 2010-2024 Grigory Chudov.
This is free software under the GNU GPLv3+ license; There is NO WARRANTY, to
the extent permitted by law. <http://www.gnu.org/licenses/> for details.
Filename : 09 - Year Of The Cat.wav
File Info : 96000 Hz; 6 channel; 24 bit; 00:06:39.2960000
Device : NVIDIA GeForce RTX 4090, Platform: "NVIDIA CUDA", Version: OpenCL 3.0 CUDA 12.7.33, Driver: 566.36
Results : 192.22x; 347923390 bytes in 00:00:02.0773098 seconds;

Sample file:

D:\Burn>"C:\Program Files\CUETools_2.2.6\CUETools.FLACCL.cmd.exe" -11 --lax --fast-gpu "clproblem.wav"
CUETools FLACCL 2.2.6, Copyright (C) 2010-2024 Grigory Chudov.
This is free software under the GNU GPLv3+ license; There is NO WARRANTY, to
the extent permitted by law. <http://www.gnu.org/licenses/> for details.
Filename : clproblem.wav
File Info : 44100 Hz; 2 channel; 16 bit; 00:18:36.7000000
Device : NVIDIA GeForce RTX 4090, Platform: "NVIDIA CUDA", Version: OpenCL 3.0 CUDA 12.7.33, Driver: 566.36
Results : 2745.81x; 210146 bytes in 00:00:00.4066926 seconds;

However, I used the previous 2.2.6 build (from 2024-06-28) and couldn't reproduce it there either. ¯\_(ツ)_/¯

@ledoge
Copy link
Author

ledoge commented Dec 31, 2024

@agressiv The issue doesn't result in the encoder dying, but it does produce a broken file. Adding -o output.flac --verify to the arguments, or omitting --verify and then running flac -t output.flac, should show an error.

Also note: when you're testing different versions, to make sure that you're actually running the flac.cl file from the build you're testing and not a different cached one, you should update the timestamp on flac.cl by either changing something in the file and saving it or using something like the *nix touch command.

@agressiv
Copy link

I have the two different builds of 2.2.6 separated for testing. I still can't reproduce the error on the older june build.

D:\Burn>flac -s -d clproblem.flac -c | "C:\OldCUETools_2.2.6\CUETools.FLACCL.cmd.exe" - -11 --lax --fast-gpu --ignore-chunk-sizes --verify -o clproblem1.flac
CUETools FLACCL 2.2.6, Copyright (C) 2010-2024 Grigory Chudov.
This is free software under the GNU GPLv3+ license; There is NO WARRANTY, to
the extent permitted by law. <http://www.gnu.org/licenses/> for details.
Filename : -
File Info : 44100 Hz; 2 channel; 16 bit; 00:00:00
Device : NVIDIA GeForce RTX 4090, Platform: "NVIDIA CUDA", Version: OpenCL 3.0 CUDA 12.7.33, Driver: 566.36
Results : 1281.22x; 208126 bytes in 00:00:00.8715941 seconds;

D:\Burn>flac -t clproblem1.flac

flac 1.3.4
Copyright (C) 2000-2009 Josh Coalson, 2011-2016 Xiph.Org Foundation
flac comes with ABSOLUTELY NO WARRANTY. This is free software, and you are
welcome to redistribute it under certain conditions. Type flac' for details.`

clproblem1.flac: ok

@agressiv
Copy link

If I roll back to 2.25, I get this:

D:\Burn>flac -s -d clproblem.flac -c | "C:\CUETools_2.2.5\CUETools.FLACCL.cmd.exe" - -11 --lax --fast-gpu --ignore-chunk-sizes --verify -o clproblem2.flac
CUETools FLACCL 2.2.5, Copyright (C) 2010-2023 Grigory Chudov.
This is free software under the GNU GPLv3+ license; There is NO WARRANTY, to
the extent permitted by law. <http://www.gnu.org/licenses/> for details.
Filename  : -
File Info : 44100 Hz; 2 channel; 16 bit; 00:00:00
Device    : NVIDIA GeForce RTX 4090, Platform: "NVIDIA CUDA", Version: OpenCL 3.0 CUDA 12.7.33, Driver: 566.36
Progress  : 100%; 1362.29x; 00:00:00.7897904/00:00:00.7900000
Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at CUETools.Codecs.BitReader.read_rice_block(Int32 n, Int32 k, Int32* r)
   at CUETools.Codecs.Flake.AudioDecoder.decode_residual(BitReader bitreader, FlacFrame frame, Int32 ch)
   at CUETools.Codecs.Flake.AudioDecoder.decode_subframe_lpc(BitReader bitreader, FlacFrame frame, Int32 ch)
   at CUETools.Codecs.Flake.AudioDecoder.decode_subframes(BitReader bitreader, FlacFrame frame)
   at CUETools.Codecs.Flake.AudioDecoder.DecodeFrame(Byte[] buffer, Int32 pos, Int32 len)
   at CUETools.Codecs.FLACCL.AudioEncoder.process_result(FLACCLTask task)
   at CUETools.Codecs.FLACCL.AudioEncoder.do_output_frames(Int32 nFrames)
   at CUETools.Codecs.FLACCL.AudioEncoder.DoClose()
   at CUETools.Codecs.FLACCL.AudioEncoder.Close()
   at CUETools.FLACCL.cmd.Program.Main(String[] args)

I don't get this with any of my files, just clproblem.flac.

@agressiv
Copy link

And yes, if I remove --fast-gpu, 2.2.5 works just fine.

@c72578
Copy link
Collaborator

c72578 commented Jan 4, 2025

If I roll back to 2.25, I get this:

@agressiv thanks for the additional information concerning reproducibility of the issue using CUETools releases 2.2.6 and 2.2.5.

Concerning CUETools 2.2.5:
If you replace C:\CUETools_2.2.5\plugins\flac.cl with the updated flac.cl from the PR here, does it work then?

@agressiv
Copy link

agressiv commented Jan 4, 2025

If you replace C:\CUETools_2.2.5\plugins\flac.cl with the updated flac.cl from the PR here, does it work then?

No, it still gives the same unhandled exception.

If I copy CUETools.Codecs.FLACCL.dll from either build of 2.2.6, that gets rid of it, even if flac.cl is left alone at 2.2.5.

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

Successfully merging this pull request may close these issues.

Found a file that causes crash of encoder at certain settings
4 participants