Unreasonable code in cv::String::String(const std::string& str, size_t pos, size_t len) (Bug #4488)


Added by Jingwei Yang over 9 years ago. Updated over 9 years ago.


Status:Done Start date:2015-07-16
Priority:Normal Due date:
Assignee:- % Done:

100%

Category:core
Target version:3.0
Affected version:branch 'master' (3.0-dev) Operating System:Windows
Difficulty: HW Platform:x64
Pull request:https://github.com/Itseez/opencv/pull/4202

Description

Unreasonable code logic in the code below, located at "...\modules\core\include\opencv2\core\cvstd.inl.hpp", line 85.

inline
String::String(const std::string& str, size_t pos, size_t len)
    : cstr_(0), len_(0)
{
    size_t strlen = str.size();
    pos = max(pos, strlen);
    len = min(strlen - pos, len);
    if (!len) return;
    memcpy(allocate(len), str.c_str() + pos, len);
}

I suppose that pos = max(pos, strlen); should be pos = min(pos, strlen); instead, as pos should never exceed strlen.

Typically "cvstd.inl.hpp" appears as "...\build\include\opencv2\core\cvstd.inl.hpp" and is included by "...\build\include\opencv2\core.hpp" at line 3107.


History

Updated by Philipp Hasper over 9 years ago

Thanks for reporting, this is the fix: https://github.com/Itseez/opencv/pull/4202
(off-topic: why can't I change the "Pull request" field of a ticket?)

  • % Done changed from 0 to 100
  • Status changed from New to Open

Updated by Maksim Shabunin over 9 years ago

  • Pull request set to https://github.com/Itseez/opencv/pull/4202

Updated by Alexander Alekhin over 9 years ago

  • Status changed from Open to Done

Also available in: Atom PDF