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

Constant attr to visitor #3540

Merged
merged 8 commits into from
Dec 23, 2020

Conversation

pelszkow
Copy link
Contributor

@pelszkow pelszkow commented Dec 9, 2020

Ticket: 40740

@pelszkow pelszkow requested review from jdanieck and sdurawa December 9, 2020 14:43
@pelszkow pelszkow force-pushed the constant_attr_to_visitor branch 6 times, most recently from 6f35598 to 81f4850 Compare December 15, 2020 06:48
@pelszkow pelszkow force-pushed the constant_attr_to_visitor branch from 81f4850 to 22a2cf9 Compare December 15, 2020 10:19
@pelszkow pelszkow marked this pull request as ready for review December 15, 2020 10:19
@pelszkow pelszkow requested review from a team December 15, 2020 10:19
@pelszkow pelszkow requested review from sdurawa and jdanieck December 16, 2020 12:55
@pelszkow pelszkow requested a review from iefode December 16, 2020 14:03

// Return false because we didn't change nGraph Function
return false;
}

namespace {
std::string bestBinPath(const std::string &xmlPath, const std::string &binPath) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@pelszkow please explain why you need this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because some e2e tests are failing. Some test pass empty path here.

void serialize(const std::string& xmlPath, const std::string& binPath = "") const {

Copy link
Contributor

Choose a reason for hiding this comment

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

@ilyachur what is expected behaviour of InferenceEngine::CNNNetwork::serialize() when binPath is empty? It's not really specified.

Copy link
Contributor

Choose a reason for hiding this comment

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

I propose that we need to create the bin file with the same name as xml file if bin path is empty.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok. So current approach is OK - .xml is replaced with .bin.

There is one issue though, we don't check that xml path is valid, and malicious user can pass shorter than 3 character string and we will have out of bounds access.

I would do what follows:
if (xml_path is not valid path (non-empty + alphanumeric characters only?) )
throw
else if (xml_path ends with .xml)
bin_path = xml_path with replaced .xml with .bin
else
bin_name = xml_path + ".bin"

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should have the next logic:

if (bin_path is empty) {
    if (xml_path is not valid path (non-empty + alphanumeric characters only?) )
        throw
    else if (xml_path ends with .xml)
        bin_path = xml_path with replaced .xml with .bin
    else
        // Looks like if xml_path doesn't have .xml as an extension it is not valid path
        throw
}

Copy link
Contributor Author

@pelszkow pelszkow Dec 23, 2020

Choose a reason for hiding this comment

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

I have just realize that we are discuss about filename validation and not about whole path (with filename). / or c:\ are not alnum only.
When I add this validation I get error:

[ ERROR ] Can't get executable graph: Check 'std::all_of(begin(path), end(path), [](char c) { return std::isalnum(c); })' failed at ../inference-engine/src/transformations/src/transformations/serialize.cpp:517:
Filename for xml file contains invalid characters (alnum valid only): "/mnt/data/workspace/openvino/openvino/build/install/deployment_tools/exec_graph.xml"

Copy link
Contributor

Choose a reason for hiding this comment

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

@pelszkow Did you fix the issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, I drop isalnum path validation idea. Without this validation (is not present in master) all works fine.

Copy link
Contributor

@iefode iefode left a comment

Choose a reason for hiding this comment

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

IE test part LGTM


// Return false because we didn't change nGraph Function
return false;
}

namespace {
std::string bestBinPath(const std::string &xmlPath, const std::string &binPath) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ok. So current approach is OK - .xml is replaced with .bin.

There is one issue though, we don't check that xml path is valid, and malicious user can pass shorter than 3 character string and we will have out of bounds access.

I would do what follows:
if (xml_path is not valid path (non-empty + alphanumeric characters only?) )
throw
else if (xml_path ends with .xml)
bin_path = xml_path with replaced .xml with .bin
else
bin_name = xml_path + ".bin"

@ilyachur ilyachur merged commit 2bc18c2 into openvinotoolkit:master Dec 23, 2020
@pelszkow pelszkow deleted the constant_attr_to_visitor branch January 11, 2021 06:35
mryzhov pushed a commit to mryzhov/openvino that referenced this pull request Jan 14, 2021
* Add new path for constant in IR serializer.

* Apply suggestion from review.

* Unique name for temporary test file

* Switch from static to constant member function - GetTestName

* Ensure bin path is not empty.

* Compare Constants op by string values converted to float.

* Add path validation.

Co-authored-by: Patryk Elszkowski <[email protected]>
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.

5 participants