-
Notifications
You must be signed in to change notification settings - Fork 42
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
impossibly long duration with crafted midi file #200
Comments
send_output() is a function pointer, not a function of its own:
This is incorrect: if send_output() returns negative there is the
[...]
I cannot reproduce this with your attached hang_main_00 as input: |
Could not reproduce on x86_64 Fedora 27, either. |
Apologises, the uploaded POC was incorrect, we have removed it. Corrected - https://github.com/SegfaultMasters/covering360/blob/master/wildmidi/1_hang_main_00 Using Ubuntu 16.04 LTS 64bit Caution - This issue may consume too much memory of your disk |
Reproduced. Although the issue is not related to any of the output @chrisisonwildcode , this is for you I think. |
This seems like a security issue when wildmidi is used with other applications, we can say it as excessive memory consumption. And I do agree, the issue is with midi parsing |
Further info:
|
Thanks for the further clarification. |
Last release from the 0.4 series is 0.4.2, so that should be it I guess: @psi29a? |
For libtimidity, there is a signed integer overflow, found thanks
In wildmidi, ubsan didn't help because things are unsigned. |
Three things I want to hash out so everybody knows where I am at in the dev cycle. Firstly, yes I guess it is theoretically possible to unsigned integer overflow wildmidi by using a crafted midi file. The way to prevent this would be to hard code an upper limit on delta times. what is the longest piece of music in existence to date? Also there shouldn't(quotations) be excessive memory consumption unless the lib is being abused by the calling application, for example our example player only gets the lib to process chunks of audio at a time. The only way to prevent abuse of the lib would be to limit the length of audio data it will process at a time forcing the calling app to ask for chunks instead of the whole thing at once. Secondly, I am slowly working on a side project that will help to reverse engineer file formats and debug issues with those formats including the incredibly long reported file times. While planned for a while it is still in its infancy but moving into alpha status within the next month or 2 as key parts are written and tested. Again the side project will (underline/bold) greatly help move wildmidi forward with debugging current issues with currently supported formats and help with development for future supported formats. It will not be a part of wildmidi as its usability goes way beyond what we do with wildmidi. Thirdly, the delta times that create the incredibly long file times occur after the last event that influences any note. If I remember there is an option to "trim the fat" and when used with those files they report a more respectable time. There are conflicting opinions about the cause of the long delta times hence the side project in my second point. |
See wildmidi bug 'impossibly long duration with crafted midi file': Mindwerks/wildmidi#200 Without this patch, the following file gives 60815401 msecs duration: https://github.com/SegfaultMasters/covering360/blob/master/wildmidi/1_hang_main_00 With this patch it simply doesn't load. Note #1: This does not help cases where crafted midi files would have crazy delta times but not cause integer overflows which still would result in crazy durations and crazy memory allocations. Note #2: I only hit the first (multiplication) overflow, but not the second (addition) one. Timidity++, on the other hand, checks only the addition overflow, and it does that by checking the result 'st' for being negative - it seems to work there..
I agree: there is not a foolproof way of truly 'fixing' this. For the record, I pushed the following patch to fix the signed int |
Is there any way for us to test and confirm the patch solves the issue? I see it is libtimidity but not wildmidi though |
No: because there is no patch for wildmidi yet.
Yes, I specifically said that it is so. |
There was a midi file that just looped itself for 300+ minutes... perfectly valid. Should we put in an arbitrary limit on wave-out with an additional flag that more or less says: I know what I'm doing, render this super long file that will eat my 10TiB HDD? This means that playback is not effected, only wave-out/write to disk. |
Don't know, but I have a feeling that that might make things unnecessarily complex. What I wonder is how 0.3.14 is not affected by this. |
Hmmm... |
I'm torn on this one because there is nothing wrong with a long midi file. |
Should we close as WONTFIX ? |
Totally agree that it's an expected behavior, but I strongly believe the user should be well aware of the size of the output file to be generated. Secondly, even SIGINT doesn't stop the program, we need to kill the process in order to stop the file generation.
This fix sounds good. |
If this is running the wildmidi player binary, hitting 'q' stops it just fine. |
True, only if the user is using wildmidi binary running on CLI. But if wildmidi is used in any web applications (in nodejs) cannot kill the process, instead, it consumes a lot of memory. Would you agree if I say that we can leverage wildimidi usage to convert files via online just like other online converters |
I'll defer to the wisdom of project owners for this one. |
I'm comfortable with a default limit of 1GiB, high enough to contain most midi files. Anything larger than this requires an extra flag (via player and lib) to by-pass limit. I'm still curious as to why this isn't a problem for 3.x, do we not loop there? |
As am I. Another question is whether this is a dup of #176 somehow (how?)??.. |
What does 0.3.x do when trying to play back this midi file? (I haven't yet tested.) Does it write anything to disk? Does it error out? |
It just plays it it and exits cleanly for me. (Try yourself.) |
Yes, but doesn't write to disk? That's the problem right... writing out to disk? |
Why do you think that it doesn't write to disk? Running wildmidi with the -o switch writes a small wav file and exits cleanly. (Try yourself.) |
For me, wildmidi-0.3.14 produces a 1572264 bytes wav file with default rate and channels using an old version of eaw patches. |
I misunderstood. Waiting for additional information from @chrisisonwildcode since he seems to be on track there as well. |
Hey there, is there any update on fixing this issue. Just curious to know |
We're waiting @chrisisonwildcode to look at things, so I gather it'll take some time :( |
Created PR #220 for this. |
An inline function
wmidi_write()
called bywrite_wav_output()
fromsend_output()
at line 2063 inwildmidi.c
is recursively being called inside a while loop as no break statement is issued, results in generating a WAV file of unrestricted size, causing the system to hang up.Affected version:
0.4.3 (Master)
Command:
wildmidi -o /home/aceteam/wildmidi/some.WAV $POC
Debugging
Backtrace:
Please do confirm if you are able to reproduce the issue with this Reproducer
The text was updated successfully, but these errors were encountered: