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

Don't allow invalid project files! #2523

Merged
merged 1 commit into from
Sep 5, 2016

Conversation

zonkmachine
Copy link
Member

The renderer hangs bad if you give it something that isn't an LMMS project as argument.


Loading project...
Done
|-                                 |      0%   \   <---infinite hang here!

This fix tests that the given file is really a file ( not a directory ). It also tests for a valid LMMS project suffix.

~/builds/lmms/build$ ./lmms -r ../build
The file ../build does not exist!

You can test specifically for if the argument is a directory and report accordingly but that would be over doing it a bit I think.

~/builds/lmms/build$ ./lmms -r ../build/lmmscon
The file ../build/lmmscon does not exist!
~/builds/lmms/build$ ./lmms -r ../build/lmmsconfig.h 
../build/lmmsconfig.h is not an LMMS project fil

I finally moved the line Engine::init( true ); to after the tests as it just felt like a better place.

@zonkmachine zonkmachine added this to the 1.2.0 milestone Jan 28, 2016
@zonkmachine zonkmachine changed the title Don't allow crap as render argument! Don't allow invalid arguments to the renderer! Jan 28, 2016
@tresf
Copy link
Member

tresf commented Jan 28, 2016

Looks good. 👍 I'll leave time for comments. One thought was the posiblity of loading a non-mmp or non-mmpz file, but loadFile only takes projects, so that's for another time. 👍

@zonkmachine
Copy link
Member Author

One thought was the posiblity of loading a non-mmp or non-mmpz file,

Yes, I was going to ask about it.
I'm currently trying to move the whole file test to here. Right after fileToLoad is assigned a file.
We're currently treating file arguments for render and load differently and this should fix it. It works but I haven't tested it thoroughly. It probably makes the larger part of #2524 redundant

@zonkmachine
Copy link
Member Author

In the last version it still tests for an empty fileToLoad if you choose --import and halts with a
The file does not exist!

@zonkmachine zonkmachine changed the title Don't allow invalid arguments to the renderer! Don't allow invalid project file arguments! Jan 29, 2016
@zonkmachine zonkmachine changed the title Don't allow invalid project file arguments! Don't allow invalid project files! Jan 29, 2016
@zonkmachine
Copy link
Member Author

importsuffixes

Same checks for files to import.

@zonkmachine
Copy link
Member Author

One thought was the posiblity of loading a non-mmp or non-mmpz file

An mpt file?

@softrabbit
Copy link
Member

An mpt file?

Any valid LMMS project file that happens to be named differently from what's expected? If I explicitly tell LMMS to load a file called "myproject.mmpx" or whatever, I expect it to at least try and not reject the file until it's at least opened the file and tried parsing it.

@zonkmachine
Copy link
Member Author

Any valid LMMS project file that happens to be named differently from what's expected? If I explicitly tell LMMS to load a file called "myproject.mmpx" or whatever, I expect it to at least try and not reject the file until it's at least opened the file and tried parsing it.

OK. Right now if you try and save a project file with another suffix than .mmp or .mmpz, it will stick a new suffix after the one you opted for. In your case with myproject.mmpx you will get myproject.mmpx.mmpz so on my Ubuntu/Mint I have to go back and change suffix manually and then myproject.mmpx will open as you expect it. Either as a command line argument or from the gui.

Edit: Only files ending mmp/mmpz will show up in the file open dialogue so other valid projects will have to be loaded from the command line.

fileInfoImport.suffix().toLower() == "midi" ||
fileInfoImport.suffix().toLower() == "rmi" ||
fileInfoImport.suffix().toLower() == "flp" ||
fileInfoImport.suffix().toLower() == "h2song" ) )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm.... Every time I see a laundry list of file extensions I get worried that we're making more work for ourselves down the road. 😄 Perhaps related to this PR, perhaps not.... can we start managing our extension in a centralized place? We should be able to use #ifdef's to enable/disable them globally based on what libraries/plugins cmake finds. We already do this in several other places already. Food for thought.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps related to this PR, perhaps not.... can we start managing our extension in a centralized place?

Related but it doesn't sound like something I can implement.

@zonkmachine zonkmachine force-pushed the directoryargument branch from 9600c50 to 4a3fca6 Compare May 5, 2016 00:37
@zonkmachine
Copy link
Member Author

Conflicts resolved.

@zonkmachine zonkmachine force-pushed the directoryargument branch from 4a3fca6 to 080119c Compare May 5, 2016 21:27
@Umcaruje
Copy link
Member

Umcaruje commented Jul 8, 2016

@zonkmachine is there any more work needed to be done here, or it could be tested and merged?

@zonkmachine
Copy link
Member Author

Yes, mad sorry about the slow response here. Short on time. I'll look into it as soon as I possibly can.

@zonkmachine
Copy link
Member Author

OK. Trying to finish this one now.

@zonkmachine zonkmachine force-pushed the directoryargument branch 2 times, most recently from 94d106a to 2bcda0e Compare July 18, 2016 06:07
}
else if( !( fileInfoLoad.suffix().toLower() == "mmp" ||
fileInfoLoad.suffix().toLower() == "mmpz" ||
fileInfoLoad.suffix().toLower() == "mpt" ) )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Older projects use the xml extension.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@jasp00
Copy link
Member

jasp00 commented Jul 21, 2016

Current fix is incomplete. Input file could be an empty file, the empty template, a broken project or a different XML file. I do not think these new checks are necessary. The check for empty projects on export should be enough.

@jasp00
Copy link
Member

jasp00 commented Jul 21, 2016

I do not think these new checks are necessary.

I mean checking the extension, if the input does not exists, etc.

@zonkmachine
Copy link
Member Author

zonkmachine commented Aug 9, 2016

Right, back on this...

Input file could be an empty file,

Hm, missed that. Poking around with it right now...

the empty template

...Will open correctly.

a broken project

A file that is empty or a broken project will be passed to LMMS who will fail to open it and report on it.

emptyproject

It will then open an empty project with the title of the project you tried to open.

@jasp00
Copy link
Member

jasp00 commented Aug 9, 2016

I mean that rendering those invalid projects (empty file, empty template, etc.) with lmms -r causes the infinite hang.

@zonkmachine
Copy link
Member Author

Right. In the case of an empty file the latest commit proposed a fix and it's working. An empty template however, I think goes a bit beyond this PR. Shouldn't it rather be catched by the renderer?

@zonkmachine
Copy link
Member Author

When exporting from the gui lmms ran TrackContainer::isEmpty() so I added this test in main.


$ ./lmms --rendertracks empty.mmpz
Notice: could not set realtime priority.
VST sync support disabled in your configuration
Loading project...
The project empty.mmpz is empty, aborting!

else if( !( fileInfoLoad.suffix().toLower() == "mmp" ||
fileInfoLoad.suffix().toLower() == "mmpz" ||
fileInfoLoad.suffix().toLower() == "mpt" ||
fileInfoLoad.suffix().toLower() == "xml" ) )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having one of these extensions is not required; this check should be removed. The Engine::getSong()->isEmpty() check takes care of invalid projects.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I initially made these suffix tests because lmms opens in an unclean manner when you throw a file whatever at it. It will open a blank project with the title you just gave it. I think at least we should not set the project title when the project couldn't be opened.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will open a blank project with the title you just gave it. I think at least we should not set the project title when the project couldn't be opened.

That's a regression from 1.1.3 which does this just fine...

@zonkmachine zonkmachine force-pushed the directoryargument branch 2 times, most recently from 9e0cccc to d06f253 Compare September 1, 2016 17:38
{
fileCheck( fileToLoad );
}
if( !fileToImport.isEmpty() )
Copy link
Member Author

@zonkmachine zonkmachine Sep 1, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else if

Should I short this one out and give fileToLoad priority?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, fixed that...

{
printf("The project %s is empty, aborting!\n", fileToLoad.toUtf8().constData() );
exit( EXIT_FAILURE );
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is exit() even a good way to terminate the application at this point?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may omit exit() and avoid the export, so an upgraded .lmmsrc.xml can be written, but exit() (or return) is not a bad way.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oK. I just skimmed past some comment on the net that exit() could be a problem with multi threaded applications. I'm happy with .lmmsrc.xml not being written so we keep failing loads from appearing in the recently opened projects list.

@zonkmachine
Copy link
Member Author

zonkmachine commented Sep 2, 2016

lmms used to load default.mmp on failing to load a project but this was broken in commit: 2c7036e#diff-1c0d925f7437a8e3a837c0a991b4cf34

I'll try and look into the original issue (Edit: #781) behind that PR

Edit2: Fix for this in #3013

@zonkmachine
Copy link
Member Author

It's better to not inflate this PR. The regression in Song.cpp is not directly related to these fixes so I'll treat them separately.

Rebased and squashed! 🚜

@jasp00
Copy link
Member

jasp00 commented Sep 4, 2016

This request may be merged.

@zonkmachine zonkmachine merged commit a53fd26 into LMMS:master Sep 5, 2016
@zonkmachine
Copy link
Member Author

🚜

@zonkmachine zonkmachine deleted the directoryargument branch September 5, 2016 14:02
sambler added a commit to sambler/lmms that referenced this pull request Sep 19, 2016
* master: (213 commits)
  Update Pattern and AutomationPattern length (LMMS#3037)
  Refresh i18n strings
  Hint text update
  Drop notes with length zero (LMMS#3031)
  Background tweak
  Background
  Update Flanger
  Exclude .ts files from the Github linguist
  Redesign Multitap echo (LMMS#3008)
  Update i18n source strings
  Extended arpeggiator functions (LMMS#2130)
  Fix sample track playback in BB tracks (LMMS#3023)
  Sort plug-in embedded resources (LMMS#3014)
  Implement version major.minor.release-stage.build (LMMS#3011)
  Fix regressions on loading broken projects (LMMS#3013)
  Improved file input validation. (LMMS#2523)
  Fix sample track view in BB editor (LMMS#3002)
  Request change in model when dropping a track (LMMS#3000)
  Add LocklessAllocator and use it in LocklessList (LMMS#2998)
  Drop forceStep in AutomatableModel (LMMS#3010)
  ...
sdasda7777 pushed a commit to sdasda7777/lmms that referenced this pull request Jun 28, 2022
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.

5 participants