Skip to content

Commit e893ae0

Browse files
committed
JSVideo : Fix crash on access to uninitialized properties (width & height)
1 parent 9ba0d6f commit e893ae0

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/Binding/JSVideo.cpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -209,14 +209,22 @@ bool JSVideo::JSGetter_canvas(JSContext *cx, JS::MutableHandleValue vp)
209209

210210
bool JSVideo::JSGetter_width(JSContext *cx, JS::MutableHandleValue vp)
211211
{
212-
vp.setInt32(this->m_Video->m_CodecCtx->width);
212+
if (m_Video->m_CodecCtx) {
213+
vp.setInt32(m_Video->m_CodecCtx->width);
214+
} else {
215+
vp.setInt32(-1);
216+
}
213217

214218
return true;
215219
}
216220

217221
bool JSVideo::JSGetter_height(JSContext *cx, JS::MutableHandleValue vp)
218222
{
219-
vp.setInt32(this->m_Video->m_CodecCtx->height);
223+
if (m_Video->m_CodecCtx) {
224+
vp.setInt32(this->m_Video->m_CodecCtx->height);
225+
} else {
226+
vp.setInt32(-1);
227+
}
220228

221229
return true;
222230
}

tests/jsunittest/AV/Video.js

+15
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ Tests.registerAsync("Video.open(invalid file)", function(next) {
2121
video.open("invalid");
2222
}, 5000);
2323

24+
Tests.register("Video access to uninitialized properties", function() {
25+
Assert.strictEqual(video.width, -1, "Video width does not match");
26+
Assert.strictEqual(video.height, -1, "Video height does not match");
27+
Assert.strictEqual(video.duration, 0, "Video duration is incorrect");
28+
Assert.strictEqual(video.bitrate, 0, "Unexpected bitrate");
29+
Assert.strictEqual(video.metadata, undefined, "File MetaData does not match");
30+
Assert.strictEqual(video.getAudioNode(), null, "Node should not be defined");
31+
});
32+
33+
2434
Tests.registerAsync("Video.open", function(next) {
2535
video.close();
2636

@@ -40,6 +50,11 @@ Tests.registerAsync("Video.open", function(next) {
4050
video.open("AV/video.ogg");
4151
}, 5000);
4252

53+
Tests.register("Video.width/height", function() {
54+
Assert.strictEqual(video.width, 720, "Video width does not match");
55+
Assert.strictEqual(video.height, 400, "Video height does not match");
56+
});
57+
4358
Tests.register("Video.duration", function() {
4459
Assert.strictEqual(video.duration, 6, "Video duration is incorrect");
4560
});

0 commit comments

Comments
 (0)