-
Notifications
You must be signed in to change notification settings - Fork 0
/
test - Copy (2).html
139 lines (121 loc) · 3.35 KB
/
test - Copy (2).html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
</head>
<body>
<video controls></video>
<script src=//cdnjs.cloudflare.com/ajax/libs/seedrandom/2.3.10/seedrandom.min.js></script>
<script>
function sha256(imageData) {
return crypto.subtle.digest("SHA-256", imageData.data).then(function (hash) {
return hex(hash);
});
}
function hex(buffer) {
var hexCodes = [];
var view = new DataView(buffer);
for (var i = 0; i < view.byteLength; i += 4) {
var value = view.getUint32(i)
var stringValue = value.toString(16)
var padding = '00000000'
var paddedValue = (padding + stringValue).slice(-padding.length)
hexCodes.push(paddedValue);
}
return hexCodes.join("");
}
function getHash(cb) {
console.log("gethash");
var canvas = document.createElement('canvas');
canvas.height = video.videoHeight;
canvas.width = video.videoWidth;
var ctx = canvas.getContext('2d');
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
try {
var data = ctx.getImageData(0, 0, canvas.width, canvas.height);
sha256(data).then(function(digest) {
hashes.push(digest);
if(digest == "0b150fd32588b1daca5569992ebe559c0102c837306b1af4c44d35128ec58366") count++;
cb();
}, function(error) {
hashes.push(error.toString());
cb();
});
} catch(e) {
hashes.push(e.toString());
cb();
}
}
Math.seedrandom('hello.');
var buffer = null;;
var sourceBuffer;
var video = document.querySelector('video');
var mediaSource;
var fuzzed;
var i = 1000;
var crashes = [];
var hashes = [];
var assetURL = 'frag_bunny.mp4';
var mimeCodec = 'video/mp4; codecs="avc1.42e01e, mp4a.40.2"';
var count = 0;
function fuzz() {
var buf = buffer.slice(0);
var view = new DataView(buf);
i+=1;
console.log(i);
view.setUint8(i, 0);
return buf;
}
function fetchAB (url, cb) {
var xhr = new XMLHttpRequest;
xhr.open('get', url);
xhr.responseType = 'arraybuffer';
xhr.onload = function () {
cb(xhr.response);
};
xhr.send();
};
function setup() {
if ('MediaSource' in window && MediaSource.isTypeSupported(mimeCodec)) {
mediaSource = new MediaSource;
video.src = URL.createObjectURL(mediaSource);
mediaSource.addEventListener('sourceopen', sourceOpen);
} else {
console.error('Unsupported MIME type or codec: ', mimeCodec);
}
}
function sourceOpen (_) {
var mediaSource = this;
mediaSource.removeEventListener('sourceopen', sourceOpen);
sourceBuffer = mediaSource.addSourceBuffer(mimeCodec);
sourceBuffer.addEventListener('updateend', updateEnd);
if(buffer === null) {
fetchAB(assetURL, function (buf) {
buffer = buf;
fuzzed = fuzz();
sourceBuffer.appendBuffer(fuzzed);
});
} else {
fuzzed = fuzz();
sourceBuffer.appendBuffer(fuzzed);
}
}
function updateEnd (_) {
if(mediaSource.duration > 0) {
getHash(setup);
//setup();
} else {
crashes.push(i);
if(crashes.length < 20) {
setup();
} else {
document.body.innerHTML = "<pre>" + JSON.stringify(crashes, undefined, 2) + "</pre>";
document.body.innerHTML += "<pre>" + JSON.stringify(hashes, undefined, 2) + "</pre>";
document.body.innerHTML += "<pre>" + count + "</pre>";
}
}
}
setup();
</script>
</body>
</html>