Skip to content

fix(audio): add length check for MLT track loading - #3512

Merged
morevnaproject merged 7 commits into
synfig:masterfrom
Abdelhadi-Wael:fix-file-header-validation
Apr 13, 2025
Merged

morevnaproject merged 7 commits into
synfig:masterfrom
Abdelhadi-Wael:fix-file-header-validation

Conversation

@Abdelhadi-Wael

@Abdelhadi-Wael Abdelhadi-Wael commented Mar 11, 2025 •

Copy link
Copy Markdown
Contributor

Fixes #3484

@Abdelhadi-Wael
Abdelhadi-Wael force-pushed the fix-file-header-validation branch from 1a5f42c to 5214d71 Compare March 11, 2025 21:44
@Abdelhadi-Wael

Copy link
Copy Markdown
Contributor Author

@rodolforg Could you please review this PR? Thanks!

@Abdelhadi-Wael Abdelhadi-Wael changed the title Fix file header validation in Widget_SoundWave fix(soundwave): validate file header to prevent crashes Mar 13, 2025
@github-actions

Copy link
Copy Markdown

Thank you for attempting to improve your contribution description!
Below is how your updated contribution will appear in Synfig's release notes. Review it and make further improvements until you're satisfied!

🐞 Bug Fixes

  • (Soundwave Related) Validate file header to prevent crashes

    Fixes : #3484
    This PR addresses a crash when attempting to display the sound wave of an unsupported audio format Instead of crashing, the application now properly validates the file format before processing.

@ice0

ice0 commented Mar 13, 2025

Copy link
Copy Markdown
Collaborator

the application now properly validates the file format before processing.

Synfig can import a variety of audio formats (depending on the loaded plugins and their capabilities), so checking the file header might not be sufficient. A more accurate approach to solving the problem is to ask the plugin whether it managed to load the file or not.

In this case, we are using the MLT framework to load files.
There is a check to ensure that the file has been loaded successfully, but this check turned out to be insufficient.

if (!track->get_producer() || track->get_length() <= 0) {

I have output additional details to see which parameters could be used to add another condition. Here is the output for this file (based on the information provided by MLT library):

Duration (frames): 2147483647
Frame rate: 25
Sample rate: 0
Channels: 0

I suggest adding an additional check based on the Sample rate.

@Abdelhadi-Wael

Copy link
Copy Markdown
Contributor Author

Okay, done thanks for the clarification

@ice0

ice0 commented Mar 13, 2025

Copy link
Copy Markdown
Collaborator

Looks good. Please fix the PR description to better match the changes made.

@Abdelhadi-Wael Abdelhadi-Wael changed the title fix(soundwave): validate file header to prevent crashes fix(audio): add sample rate check for MLT track loading Mar 13, 2025
@github-actions

Copy link
Copy Markdown

Thank you for attempting to improve your contribution description!
Below is how your updated contribution will appear in Synfig's release notes. Review it and make further improvements until you're satisfied!

🐞 Bug Fixes

  • (Audio Related) Add sample rate check for MLT track loading

    Fixes : #3484
    This PR addresses a crash when attempting to display the sound wave of an unsupported audio format Instead of crashing, the application now properly validates the file format before processing.

@github-actions

Copy link
Copy Markdown

Thank you for attempting to improve your contribution description!
Below is how your updated contribution will appear in Synfig's release notes. Review it and make further improvements until you're satisfied!

🐞 Bug Fixes

  • (Audio Related) Add sample rate check for MLT track loading

    Fixes : #3484
    Previously, files with an invalid sample rate (e.g., 0) could pass initial checks,causing crashes during audio processing. This update ensures only properly loaded audio files are processed by validating the sample rate.

@Abdelhadi-Wael

Copy link
Copy Markdown
Contributor Author

done

@rodolforg

Copy link
Copy Markdown
Contributor

Interesting.
The 'linux' software file detects the sample rate, as well as the Gnome nautilus when right-clicking to get file properties. Audacity imports fine too, with correct sample rate. Why MLT doesn't detect it? :/

Here is the output for this file (based on the information provided by MLT library):

Duration (frames): 2147483647
Frame rate: 25
Sample rate: 0
Channels: 0

@ice0

ice0 commented Mar 16, 2025

Copy link
Copy Markdown
Collaborator

Interesting. The 'linux' software file detects the sample rate, as well as the Gnome nautilus when right-clicking to get file properties. Audacity imports fine too, with correct sample rate. Why MLT doesn't detect it? :/

Added issue: mltframework/mlt#1073

@Abdelhadi-Wael

Abdelhadi-Wael commented Mar 17, 2025 •

Copy link
Copy Markdown
Contributor Author

I suggest adding an additional check based on the Sample rate.

The additional check based on the Sample rate didn't solve the issue, so I added a length check as well.

Hopefully, this resolves the problem. Please let me know if any further changes are needed.

@ice0

@ice0

ice0 commented Mar 23, 2025

Copy link
Copy Markdown
Collaborator

The additional check based on the Sample rate didn't solve the issue

I suggest removing this check since it doesn't work, to avoid cluttering the code.

I also suggest getting rid of the magic number (2147483647) and doing something like this (to improve clarity).

// That value is INT_MAX, which is our special value that means unknown or possibly a live source.
// https://github.com/mltframework/mlt/issues/1073#issuecomment-2730111264
constexpr int mlt_error_length = INT_MAX;

@Abdelhadi-Wael Abdelhadi-Wael changed the title fix(audio): add sample rate check for MLT track loading fix(audio): add length check for MLT track loading Mar 23, 2025
@github-actions

Copy link
Copy Markdown

Thank you for attempting to improve your contribution description!
Below is how your updated contribution will appear in Synfig's release notes. Review it and make further improvements until you're satisfied!

🐞 Bug Fixes

  • (Audio Related) Add length check for MLT track loading

    Fixes #3484

1 similar comment
@github-actions

Copy link
Copy Markdown

Thank you for attempting to improve your contribution description!
Below is how your updated contribution will appear in Synfig's release notes. Review it and make further improvements until you're satisfied!

🐞 Bug Fixes

  • (Audio Related) Add length check for MLT track loading

    Fixes #3484

@Abdelhadi-Wael

Copy link
Copy Markdown
Contributor Author

I suggest removing this check since it doesn't work, to avoid cluttering the code.

added a commit : )

@ice0

ice0 commented Mar 23, 2025

Copy link
Copy Markdown
Collaborator

It failed last time because the self-hosted runner was offline.
I re-ran the job. Now should be ok.

@morevnaproject
morevnaproject merged commit 10a1391 into synfig:master Apr 13, 2025
@Abdelhadi-Wael
Abdelhadi-Wael deleted the fix-file-header-validation branch April 13, 2025 10:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Displaying the sound wave of the attached audio file crashes Synfig Studio

5 participants