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

WIP: Improved Profile file parsing and error handling #493

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

Conversation

kartchnb
Copy link

@kartchnb kartchnb commented Apr 3, 2020

Modified the Profile constructor to better identify invalid or malformed Profile files and throw more informative exceptions when issues are encountered. I will also be modifying openshot-qt to better handle these exceptions rather than failing silently.

This resolves an issue I had when a malformed Profile file caused a segmentation fault.

While I was in the code, I modified the InterpolateBetween function in KeyFrame.cpp to eliminate a compiler warning.

I modified the Profile constructor to better identify invalid or
malformed Profile files and throw more informative exceptions.

I will also be pushing a modification to openshot-qt to better handle
these exceptions.

I also modified the InterpolateBetween function in KeyFrame.cpp to
remove a compilation warning.
I made my changes to InterpolateBetween in KeyFrame.cpp less intrusive.
@codecov-io
Copy link

Codecov Report

Merging #493 into develop will decrease coverage by 0.01%.
The diff coverage is 5.55%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #493      +/-   ##
===========================================
- Coverage    48.24%   48.22%   -0.02%     
===========================================
  Files          128      128              
  Lines         9962     9965       +3     
===========================================
  Hits          4806     4806              
- Misses        5156     5159       +3     
Impacted Files Coverage Δ
src/Profiles.cpp 0.00% <0.00%> (ø)
src/KeyFrame.cpp 78.80% <50.00%> (-0.32%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 166f693...ccc31c1. Read the comment docs.

Copy link
Contributor

@ferdnyc ferdnyc left a comment

Choose a reason for hiding this comment

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

Mostly just a few minor, take-it-or-leave-it suggestions, but the "don't throw on unrecognized data" thing I'm pretty firm on. (In observance of Postel's Law.)

assert(target <= right.co.X);
assert(target <= right.co.X);
Copy link
Contributor

Choose a reason for hiding this comment

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

Drop this change, please (addition of extraneous whitespace)

Comment on lines +63 to +66
QString line = in.readLine();

// Trim any extra whitespace from the line
line = line.trimmed();
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be simpler to do this all in one go, like with the splitted parts a few lines down.

Suggested change
QString line = in.readLine();
// Trim any extra whitespace from the line
line = line.trimmed();
QString line = in.readLine().trimmed();

Comment on lines +124 to +128
else {
// Any other setting makes the file invalid
std::ostringstream oss;
oss << "Unrecognized setting \"" << setting << "\" encountered";
throw std::runtime_error(oss.str());
Copy link
Contributor

@ferdnyc ferdnyc Apr 4, 2020

Choose a reason for hiding this comment

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

Honestly, I'm pretty wary of this. Logging an unrecognized setting (using ZmqLogger::Instance()->AppendDebugMethod()) would be OK, but not bailing on the entire file.

If an unrecognized parameter is an error, then whenever we next need to extend the format with new parameters, we'll instantly have a problem with older libopenshot versions breaking if they're fed any of the new files.

For backwardsforwards-compatibility, far better if the parser simply assumes that anything it doesn't know how to process is valid data that just isn't meant for its consumption, and continue processing the rest of the file.

Comment on lines +71 to +78
if (line.contains(QChar('=')) == false) {
throw std::runtime_error("Invalid line encountered");
}

// Split current line
QStringList parts = line.split( "=" );
std::string setting = parts[0].toStdString();
std::string value = parts[1].toStdString();
std::string setting = parts[0].trimmed().toStdString();
std::string value = parts[1].trimmed().toStdString();
Copy link
Contributor

@ferdnyc ferdnyc Apr 4, 2020

Choose a reason for hiding this comment

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

Despite my previous comments about ignoring unrecognized settings, I'm fine with requiring that each line (except comments) contain an = character, since that can reasonably be considered part of the basic file format.

In fact, another way to go, rather than checking for .contains('='), would be to just always .split("=") the line, and then check that the resulting QStringList contains exactly two parts — no more, no less, as either would be an error.

Because a file accidentally left like this:

width=1280height=720
progressive=1
frame_rate_num=25
frame_rate_den=1

...should probably cause some sort of alarm to be raised.

(Unless the line is a description= line, maybe? Might be nice to special-case those so they're allowed to have arguments containing = signs. Hmm. I don't know, have to think on that.)

@kartchnb
Copy link
Author

kartchnb commented Apr 5, 2020 via email

@jonoomph
Copy link
Member

@kartchnb Would it be possible for you to wrap up these changes so I can get this merged? Thx!

@jonoomph
Copy link
Member

@kartchnb Just pinging you again on this PR. I would love to merge this if we can make those final adjustments. 👍

@jonoomph jonoomph changed the title Improved Profile file parsing and error handling WIP: Improved Profile file parsing and error handling Jan 28, 2021
@github-actions
Copy link

github-actions bot commented Jun 1, 2021

Merge conflicts have been detected on this PR, please resolve.

@github-actions github-actions bot added the conflicts A PR with unresolved merge conflicts label Jun 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conflicts A PR with unresolved merge conflicts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants