Skip to content

Commit 9665093

Browse files
authored
Merge pull request #915 from OpenShot/sentry-invalid-property-data
Prevent crash in ObjectDetection (due to NULL parentClip)
2 parents 5174608 + 2715d1c commit 9665093

File tree

6 files changed

+84
-98
lines changed

6 files changed

+84
-98
lines changed

.github/workflows/ci.yml

+12-6
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ jobs:
1111
strategy:
1212
matrix:
1313
sys:
14-
- { os: ubuntu-18.04, shell: bash }
1514
- { os: ubuntu-20.04, shell: bash }
15+
- { os: ubuntu-22.04, shell: bash }
1616
- { os: windows-2022, shell: 'msys2 {0}' }
1717
compiler:
1818
- { cc: gcc, cxx: g++ }
@@ -82,13 +82,19 @@ jobs:
8282
qtbase5-dev qtbase5-dev-tools libqt5svg5-dev \
8383
libfdk-aac-dev libavcodec-dev libavformat-dev \
8484
libavutil-dev libswscale-dev libswresample-dev \
85-
libzmq3-dev libmagick++-dev libbabl-dev \
85+
libzmq3-dev libbabl-dev \
8686
libopencv-dev libprotobuf-dev protobuf-compiler \
8787
cargo libomp5 libomp-dev
88-
# Install catch2 package from Ubuntu 20.10, since for some reason
89-
# even 20.04 only has Catch 1.12.1 available.
90-
wget https://launchpad.net/ubuntu/+archive/primary/+files/catch2_2.13.0-1_all.deb
91-
sudo dpkg -i catch2_2.13.0-1_all.deb
88+
89+
# Install catch2 package from source
90+
git clone https://github.com/catchorg/Catch2.git
91+
pushd Catch2
92+
cmake -Bbuild -H. -DBUILD_TESTING=OFF
93+
sudo cmake --build build/ --target install
94+
popd
95+
96+
wget https://launchpad.net/ubuntu/+archive/primary/+files/catch2_2.13.8-1_amd64.deb
97+
sudo dpkg -i catch2_2.13.8-1_amd64.deb
9298
9399
- name: Install macOS dependencies
94100
if: ${{ runner.os == 'macos' }}

src/Clip.cpp

+5-11
Original file line numberDiff line numberDiff line change
@@ -253,19 +253,16 @@ void Clip::AttachToObject(std::string object_id)
253253
SetAttachedClip(clipObject);
254254
}
255255
}
256-
return;
257256
}
258257

259258
// Set the pointer to the trackedObject this clip is attached to
260259
void Clip::SetAttachedObject(std::shared_ptr<openshot::TrackedObjectBase> trackedObject){
261260
parentTrackedObject = trackedObject;
262-
return;
263261
}
264262

265263
// Set the pointer to the clip this clip is attached to
266264
void Clip::SetAttachedClip(Clip* clipObject){
267265
parentClipObject = clipObject;
268-
return;
269266
}
270267

271268
/// Set the current reader
@@ -754,11 +751,8 @@ std::string Clip::PropertiesJSON(int64_t requested_frame) const {
754751
root["display"] = add_property_json("Frame Number", display, "int", "", NULL, 0, 3, false, requested_frame);
755752
root["mixing"] = add_property_json("Volume Mixing", mixing, "int", "", NULL, 0, 2, false, requested_frame);
756753
root["waveform"] = add_property_json("Waveform", waveform, "int", "", NULL, 0, 1, false, requested_frame);
757-
if (!parentObjectId.empty()) {
758-
root["parentObjectId"] = add_property_json("Parent", 0.0, "string", parentObjectId, NULL, -1, -1, false, requested_frame);
759-
} else {
760-
root["parentObjectId"] = add_property_json("Parent", 0.0, "string", "", NULL, -1, -1, false, requested_frame);
761-
}
754+
root["parentObjectId"] = add_property_json("Parent", 0.0, "string", parentObjectId, NULL, -1, -1, false, requested_frame);
755+
762756
// Add gravity choices (dropdown style)
763757
root["gravity"]["choices"].append(add_property_choice_json("Top Left", GRAVITY_TOP_LEFT, gravity));
764758
root["gravity"]["choices"].append(add_property_choice_json("Top Center", GRAVITY_TOP, gravity));
@@ -792,7 +786,7 @@ std::string Clip::PropertiesJSON(int64_t requested_frame) const {
792786
root["waveform"]["choices"].append(add_property_choice_json("No", false, waveform));
793787

794788
// Add the parentTrackedObject's properties
795-
if (parentTrackedObject)
789+
if (parentTrackedObject && parentClipObject)
796790
{
797791
// Convert Clip's frame position to Timeline's frame position
798792
long clip_start_position = round(Position() * info.fps.ToDouble()) + 1;
@@ -1440,14 +1434,14 @@ QTransform Clip::get_transform(std::shared_ptr<Frame> frame, int width, int heig
14401434

14411435
// Get the parentTrackedObject properties
14421436
if (parentTrackedObject){
1443-
14441437
// Convert Clip's frame position to Timeline's frame position
14451438
long clip_start_position = round(Position() * info.fps.ToDouble()) + 1;
14461439
long clip_start_frame = (Start() * info.fps.ToDouble()) + 1;
14471440
double timeline_frame_number = frame->number + clip_start_position - clip_start_frame;
14481441

14491442
// Get parentTrackedObject's parent clip's properties
1450-
std::map<std::string, float> trackedObjectParentClipProperties = parentTrackedObject->GetParentClipProperties(timeline_frame_number);
1443+
std::map<std::string, float> trackedObjectParentClipProperties =
1444+
parentTrackedObject->GetParentClipProperties(timeline_frame_number);
14511445

14521446
// Get the attached object's parent clip's properties
14531447
if (!trackedObjectParentClipProperties.empty())

src/TrackedObjectBBox.cpp

+4-7
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ void TrackedObjectBBox::ScalePoints(double time_scale){
235235
// Load the bounding-boxes information from the protobuf file
236236
bool TrackedObjectBBox::LoadBoxData(std::string inputFilePath)
237237
{
238-
using std::ios;
238+
using std::ios;
239239

240240
// Variable to hold the loaded data
241241
pb_tracker::Tracker bboxMessage;
@@ -282,7 +282,7 @@ bool TrackedObjectBBox::LoadBoxData(std::string inputFilePath)
282282
if (bboxMessage.has_last_updated())
283283
{
284284
std::cout << " Loaded Data. Saved Time Stamp: "
285-
<< TimeUtil::ToString(bboxMessage.last_updated()) << std::endl;
285+
<< TimeUtil::ToString(bboxMessage.last_updated()) << std::endl;
286286
}
287287

288288
// Delete all global objects allocated by libprotobuf.
@@ -381,11 +381,8 @@ void TrackedObjectBBox::SetJsonValue(const Json::Value root)
381381
protobufDataPath = root["protobuf_data_path"].asString();
382382

383383
// Set the id of the child clip
384-
if (!root["child_clip_id"].isNull() && root["child_clip_id"].asString() != "" && root["child_clip_id"].asString() != Id()){
385-
Clip* parentClip = (Clip *) ParentClip();
386-
387-
if (root["child_clip_id"].asString() != parentClip->Id())
388-
ChildClipId(root["child_clip_id"].asString());
384+
if (!root["child_clip_id"].isNull() && root["child_clip_id"].asString() != Id()){
385+
ChildClipId(root["child_clip_id"].asString());
389386
}
390387

391388
// Set the Keyframes by the given JSON object

src/TrackedObjectBase.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222

2323
namespace openshot {
2424

25-
// Forward decls
26-
class ClipBase;
25+
// Forward decls
26+
class ClipBase;
2727

2828
/**
2929
* @brief This abstract class is the base class of all Tracked Objects.
@@ -50,8 +50,8 @@ namespace openshot {
5050
/// Constructor which takes an object ID
5151
TrackedObjectBase(std::string _id);
5252

53-
/// Destructor
54-
virtual ~TrackedObjectBase() = default;
53+
/// Destructor
54+
virtual ~TrackedObjectBase() = default;
5555

5656
/// Get the id of this object
5757
std::string Id() const { return id; }

src/effects/ObjectDetection.cpp

+8-18
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ std::shared_ptr<Frame> ObjectDetection::GetFrame(std::shared_ptr<Frame> frame, i
7878
}
7979

8080
// Initialize the Qt rectangle that will hold the positions of the bounding-box
81-
std::vector<QRectF> boxRects;
82-
// Initialize the image of the TrackedObject child clip
83-
std::vector<std::shared_ptr<QImage>> childClipImages;
81+
std::vector<QRectF> boxRects;
82+
// Initialize the image of the TrackedObject child clip
83+
std::vector<std::shared_ptr<QImage>> childClipImages;
8484

8585
// Check if track data exists for the requested frame
8686
if (detectionsData.find(frame_number) != detectionsData.end()) {
@@ -122,15 +122,6 @@ std::shared_ptr<Frame> ObjectDetection::GetFrame(std::shared_ptr<Frame> frame, i
122122
std::vector<int> bg_rgba = trackedObject->background.GetColorRGBA(frame_number);
123123
float bg_alpha = trackedObject->background_alpha.GetValue(frame_number);
124124

125-
// Create a rotated rectangle object that holds the bounding box
126-
// cv::RotatedRect box ( cv::Point2f( (int)(trackedBox.cx*fw), (int)(trackedBox.cy*fh) ),
127-
// cv::Size2f( (int)(trackedBox.width*fw), (int)(trackedBox.height*fh) ),
128-
// (int) (trackedBox.angle) );
129-
130-
// DrawRectangleRGBA(cv_image, box, bg_rgba, bg_alpha, 1, true);
131-
// DrawRectangleRGBA(cv_image, box, stroke_rgba, stroke_alpha, stroke_width, false);
132-
133-
134125
cv::Rect2d box(
135126
(int)( (trackedBox.cx-trackedBox.width/2)*fw),
136127
(int)( (trackedBox.cy-trackedBox.height/2)*fh),
@@ -160,9 +151,8 @@ std::shared_ptr<Frame> ObjectDetection::GetFrame(std::shared_ptr<Frame> frame, i
160151
Clip* childClip = parentTimeline->GetClip(trackedObject->ChildClipId());
161152

162153
if (childClip){
163-
std::shared_ptr<Frame> f(new Frame(1, frame->GetWidth(), frame->GetHeight(), "#00000000"));
164154
// Get the image of the child clip for this frame
165-
std::shared_ptr<Frame> childClipFrame = childClip->GetFrame(f, frame_number);
155+
std::shared_ptr<Frame> childClipFrame = childClip->GetFrame(frame_number);
166156
childClipImages.push_back(childClipFrame->GetImage());
167157

168158
// Set the Qt rectangle with the bounding-box properties
@@ -182,15 +172,15 @@ std::shared_ptr<Frame> ObjectDetection::GetFrame(std::shared_ptr<Frame> frame, i
182172
// Update Qt image with new Opencv frame
183173
frame->SetImageCV(cv_image);
184174

185-
// Set the bounding-box image with the Tracked Object's child clip image
186-
if(boxRects.size() > 0){
175+
// Set the bounding-box image with the Tracked Object's child clip image
176+
if(boxRects.size() > 0){
187177
// Get the frame image
188178
QImage frameImage = *(frame->GetImage());
189179
for(int i; i < boxRects.size();i++){
190180
// Set a Qt painter to the frame image
191181
QPainter painter(&frameImage);
192182
// Draw the child clip image inside the bounding-box
193-
painter.drawImage(boxRects[i], *childClipImages[i], QRectF(0, 0, frameImage.size().width(), frameImage.size().height()));
183+
painter.drawImage(boxRects[i], *childClipImages[i]);
194184
}
195185
// Set the frame image as the composed image
196186
frame->AddImage(std::make_shared<QImage>(frameImage));
@@ -362,7 +352,7 @@ bool ObjectDetection::LoadObjDetectdData(std::string inputFilePath){
362352

363353
std::shared_ptr<TrackedObjectBBox> trackedObjPtr = std::make_shared<TrackedObjectBBox>(trackedObj);
364354
ClipBase* parentClip = this->ParentClip();
365-
trackedObjPtr->ParentClip(parentClip);
355+
trackedObjPtr->ParentClip(parentClip);
366356

367357
// Create a temp ID. This ID is necessary to initialize the object_id Json list
368358
// this Id will be replaced by the one created in the UI

0 commit comments

Comments
 (0)