-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Fix rlp tool failing to parse long hex string #5548
Conversation
rlp/main.cpp
Outdated
{ | ||
//filesyatem_error contains lot of error flags but I couldn't find file name too long | ||
//the closest I got was boost::system::errc -> enum errc_t -> filename_too_long = ENAMETOOLONG | ||
if(_e.what() == "File name too long") //don't know if this will work. Let's say temporary workaround. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because what()
returns a char *
you can't compare directly to a string literal here. You need to wrap the result of what
in a string object before doing the comparison.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pointing out. My bad, sorry.
But the problem still remains unaddressed, if what I am doing (Directly comparing strings) will solve this issue.
I will correct my error soon.
Codecov Report
@@ Coverage Diff @@
## release/1.6 #5548 +/- ##
===============================================
- Coverage 61.98% 61.94% -0.04%
===============================================
Files 344 344
Lines 28778 28782 +4
Branches 3269 3271 +2
===============================================
- Hits 17838 17830 -8
- Misses 9769 9776 +7
- Partials 1171 1176 +5 |
rlp/main.cpp
Outdated
string error_e = _e.what(); | ||
string long_file_name = "boost::filesystem::status: File name too long: \""; | ||
long_file_name += inputFile + "\""; | ||
if(error_e == long_file_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can probably assume that the input should be treated as bytecode if you get any error from is_regular_file
. Probably don't need to check the error message or type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And checking for error types by comparing against hard coded strings is bad form because it will break if the error message is changed upstream in Boost.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I totally agree with you regarding the hard coded strings and that change in upstream boost will break code.
But,
I thought that in here
Lines 259 to 265 in b09e9ad
if (inputFile == "--") | |
for (int i = cin.get(); i != -1; i = cin.get()) | |
in.push_back((byte)i); | |
else if (boost::filesystem::is_regular_file(inputFile)) | |
in = contents(inputFile); | |
else | |
in = asBytes(inputFile); |
contents() internally call
Lines 86 to 105 in ad7204c
template <typename _T> | |
inline _T contentsGeneric(boost::filesystem::path const& _file) | |
{ | |
_T ret; | |
size_t const c_elementSize = sizeof(typename _T::value_type); | |
boost::filesystem::ifstream is(_file, std::ifstream::binary); | |
if (!is) | |
return ret; | |
// get length of file: | |
is.seekg(0, is.end); | |
streamoff length = is.tellg(); | |
if (length == 0) | |
return ret; // do not read empty file (MSVC does not like it) | |
is.seekg(0, is.beg); | |
ret.resize((length + c_elementSize - 1) / c_elementSize); | |
is.read(const_cast<char*>(reinterpret_cast<char const*>(ret.data())), length); | |
return ret; | |
} |
contentsGeneric() and here it's performing boost::filesystem operations so boost::filesystem::filesystem_error may occur and then catching every error and handling them as filename_too_long will create another bug.
Please correct me if I am wrong.
Also I have some ideas, but I need some time to select the best out of them.
Hi, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see a bug: in case is_regular_file
returns false, in
stays empty and we don't parse anything.
Did you try to run your fix?
rlp/main.cpp
Outdated
else if (boost::filesystem::is_regular_file(inputFile)) | ||
in = contents(inputFile); | ||
} | ||
catch(const boost::filesystem::filesystem_error& _e) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
catch(const boost::filesystem::filesystem_error& _e) | |
catch (const boost::filesystem::filesystem_error& e) |
See https://github.com/ethereum/aleth/blob/master/CODING_STYLE.md
rlp/main.cpp
Outdated
} | ||
catch(const boost::filesystem::filesystem_error& _e) | ||
{ | ||
if(_e.code() == boost::system::errc::errc_t::filename_too_long) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's ok to handle all file system errors the same way (errors from contents()
, too), not only filename_too_long
rlp/main.cpp
Outdated
else | ||
in = asBytes(inputFile); | ||
|
||
try |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't make try-catch block wider than it needs to be - if you intend to handle errors from is_regular_file
only (maybe together with contents()
) - wrap only those functions in try-catch
@gumb0 is my modified code. Lines 412 to 418 in a611afe
is getting executed and as a result its falling into this catch block Lines 482 to 486 in a611afe
Declaration can be found over here Lines 74 to 108 in a611afe
I am guessing this is not a normal situation... |
@twinstar26 That was incorrect RLP I gave in the issue description, so this output is actually expected, sorry for this confusion. Try this instead:
|
@gumb0 |
For this pull request, Then for commit "1b2f222" Test Case "neighbours" failed (/Users/distiller/project/test/unittests/libp2p/net.cpp:1253: last checkpoint: "neighbours" test entry) on xcode I failed to understand the connection between the two. |
@twinstar26 there's no connection between these failures. Please ignore the second one ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@twinstar26 Please squash the commits (but pull my last commit first)
Rebased and added CHANGELOG item |
@twinstar26 please remove the last merge commit, we don't usually merge from master into implementation branches, instead we rebase branches, this helps with keeping the commit log more linear. This will be merged into master soon anyway. |
Yeah sorry I was updating my fork for solving some other issue. |
@gumb0 I reverted back. This was so embarrassing! 😅 |
Changed base to |
Fixes #5543