Skip to content

Commit 077c1a4

Browse files
PenwyRytoEX
authored andcommitted
checks: Guard float/int conversions
Converting a string to float/int will raise an exception if said string is not a valid float/int. This makes sure such exceptions are caught and do not interrupt the rest of the analysis.
1 parent d5692b0 commit 077c1a4

File tree

6 files changed

+78
-43
lines changed

6 files changed

+78
-43
lines changed

checks/audio.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ def checkAudioBuffering(lines):
4949
for i in buffering:
5050
m = audiobuf_re.search(i)
5151
if m:
52-
vals.append(int(m.group("total")))
52+
try:
53+
vals.append(int(m.group("total")))
54+
except (ValueError, OverflowError):
55+
pass
5356

5457
if (max(vals) > 500):
5558
return [LEVEL_WARNING, "High Audio Buffering",

checks/encoding.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,11 @@ def checkEncoding(lines):
118118
val = 0
119119
severity = 9000
120120
for drop in drops:
121-
v = float(drop[drop.find("(") + 1: drop.find(")")
122-
].strip('%').replace(",", "."))
121+
try:
122+
v = float(drop[drop.find("(") + 1: drop.find(")")
123+
].strip('%').replace(",", "."))
124+
except (ValueError, OverflowError):
125+
v = 0
123126
if (v > val):
124127
val = v
125128
if (val != 0):

checks/graphics.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@ def getRenderLag(lines):
1313
val = 0
1414
severity = 9000
1515
for drop in drops:
16-
v = float(drop[drop.find("(") + 1: drop.find(")")
17-
].strip('%').replace(",", "."))
16+
try:
17+
v = float(drop[drop.find("(") + 1: drop.find(")")
18+
].strip('%').replace(",", "."))
19+
except (ValueError, OverflowError):
20+
v = 0
1821
if (v > val):
1922
val = v
2023

@@ -62,27 +65,32 @@ def checkVideoSettings(lines):
6265
if "video settings reset:" in s:
6366
videoSettings.append(i)
6467
if (len(videoSettings) > 0):
68+
fmt = lines[videoSettings[-1] + 5].split()[-1]
69+
yuv = lines[videoSettings[-1] + 6].split()[-1]
70+
if 'Full' in yuv:
71+
res.append([LEVEL_WARNING, "Wrong YUV Color Range",
72+
"""Having the YUV Color range set to "Full" will cause playback issues in certain browsers and on various video platforms. Shadows, highlights and color will look off. In OBS, go to "Settings -> Advanced" and set "YUV Color Range" back to "Limited"."""])
73+
if (fmt != 'NV12' and fmt != 'P010'):
74+
res.append([LEVEL_CRITICAL, "Wrong Color Format",
75+
"Color Formats other than NV12 and P010 are primarily intended for recording, and are not recommended when streaming. Streaming may incur increased CPU usage due to color format conversion. You can change your Color Format in Settings -> Advanced."])
76+
6577
basex, basey = lines[videoSettings[-1] + 1].split()[-1].split('x')
6678
outx, outy = lines[videoSettings[-1] + 2].split()[-1].split('x')
6779
fps_num, fps_den = lines[videoSettings[-1] + 4].split()[-1].split('/')
68-
fmt = lines[videoSettings[-1] + 5].split()[-1]
69-
yuv = lines[videoSettings[-1] + 6].split()[-1]
70-
baseAspect = float(basex) / float(basey)
71-
outAspect = float(outx) / float(outy)
72-
fps = float(fps_num) / float(fps_den)
80+
try:
81+
baseAspect = float(basex) / float(basey)
82+
outAspect = float(outx) / float(outy)
83+
fps = float(fps_num) / float(fps_den)
84+
except (ValueError, OverflowError):
85+
return res # If fetching the resolution/fps fails, skip those checks
86+
7387
if ((not ((1.77 < baseAspect) and (baseAspect < 1.7787))) or (not ((1.77 < outAspect) and (outAspect < 1.7787)))):
7488
res.append([LEVEL_WARNING, "Non-Standard Aspect Ratio",
7589
"Almost all modern streaming services and video platforms expect video in 16:9 aspect ratio. OBS is currently configured to record in an aspect ratio that differs from that. You (or your viewers) will see black bars during playback. Go to Settings -> Video and change your Canvas Resolution to one that is 16:9."])
76-
if (fmt != 'NV12' and fmt != 'P010'):
77-
res.append([LEVEL_CRITICAL, "Wrong Color Format",
78-
"Color Formats other than NV12 and P010 are primarily intended for recording, and are not recommended when streaming. Streaming may incur increased CPU usage due to color format conversion. You can change your Color Format in Settings -> Advanced."])
7990
if (not ((fps == 60) or (fps == 30))):
8091
res.append([LEVEL_WARNING, "Non-Standard Framerate",
8192
"Framerates other than 30fps or 60fps may lead to playback issues like stuttering or screen tearing. Stick to either of these for better compatibility with video players. You can change your OBS frame rate in Settings -> Video."])
8293
if (fps >= 144):
8394
res.append([LEVEL_WARNING, "Excessively High Framerate",
8495
"Recording at a tremendously high framerate will not give you higher quality recordings. Usually quite the opposite. Most computers cannot handle encoding at high framerates. You can change your OBS frame rate in Settings -> Video."])
85-
if 'Full' in yuv:
86-
res.append([LEVEL_WARNING, "Wrong YUV Color Range",
87-
"""Having the YUV Color range set to "Full" will cause playback issues in certain browsers and on various video platforms. Shadows, highlights and color will look off. In OBS, go to "Settings -> Advanced" and set "YUV Color Range" back to "Limited"."""])
8896
return res

checks/macos.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,13 @@ def checkMacVer(lines):
4747
return
4848

4949
mv = "macOS %s.%s" % (html.escape(verinfo["major"]), html.escape(verinfo["minor"]))
50-
if (int(verinfo["major"]) <= 10 and "max" in verinfo):
51-
msg = "You are running %s %s, which is multiple versions out of date and no longer supported by Apple or recent OBS versions. We recommend updating to the latest macOS release to ensure continued security, functionality and compatibility." % (mv, html.escape(verinfo["name"]))
52-
mv += " (EOL)"
53-
return [LEVEL_WARNING, mv, msg]
50+
try:
51+
if (int(verinfo["major"]) <= 10 and "max" in verinfo):
52+
msg = "You are running %s %s, which is multiple versions out of date and no longer supported by Apple or recent OBS versions. We recommend updating to the latest macOS release to ensure continued security, functionality and compatibility." % (mv, html.escape(verinfo["name"]))
53+
mv += " (EOL)"
54+
return [LEVEL_WARNING, mv, msg]
55+
except (ValueError, OverflowError):
56+
pass
5457

5558
if "latest" in verinfo:
5659
msg = "You are running %s %s, which is currently supported by Apple and the most recent version of OBS." % (mv, html.escape(verinfo["name"]))

checks/network.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ def checkDrop(lines):
99
val = 0
1010
severity = 9000
1111
for drop in drops:
12-
v = float(drop[drop.find("(") + 1: drop.find(")")
13-
].strip('%').replace(",", "."))
12+
try:
13+
v = float(drop[drop.find("(") + 1: drop.find(")")
14+
].strip('%').replace(",", "."))
15+
except (ValueError, OverflowError):
16+
v = 0
1417
if (v > val):
1518
val = v
1619
if (val != 0):
@@ -58,10 +61,13 @@ def checkNICSpeed(lines):
5861
m = nicspeed_re.search(i)
5962
if m:
6063
nic = m.group("nicname")
61-
if m.group("speed"):
62-
speed = int(m.group("speed"))
63-
elif m.group("upspeed"):
64-
speed = int(m.group("upspeed"))
64+
try:
65+
if m.group("speed"):
66+
speed = int(m.group("speed"))
67+
elif m.group("upspeed"):
68+
speed = int(m.group("upspeed"))
69+
except (ValueError, OverflowError):
70+
speed = 1000
6571
if speed < 1000:
6672
if 'GbE' in nic or 'Gigabit' in nic:
6773
return [LEVEL_WARNING, "Slow Network Connection", "Your gigabit-capable network card is only connecting at 100mbps. This may indicate a bad network cable or outdated router / switch which could be impacting network performance."]

checks/windows.py

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,14 @@ def getMonitorRefreshes(lines):
4949
m = refresh_re.search(rl)
5050

5151
if m is not None:
52-
if m.group("name") is not None:
53-
output = m.group("name").strip() + " (" + str(int(m.group("output_num")) + 1) + ")"
54-
else:
55-
output = "Display " + m.group("output_num")
56-
refresh = float(m.group("refresh"))
52+
try:
53+
if m.group("name") is not None:
54+
output = m.group("name").strip() + " (" + str(int(m.group("output_num")) + 1) + ")"
55+
else:
56+
output = "Display " + m.group("output_num")
57+
refresh = float(m.group("refresh"))
58+
except (ValueError, OverflowError):
59+
continue
5760

5861
refreshes[output] = refresh
5962

@@ -130,10 +133,13 @@ def getWasapiSampleRates(lines):
130133
m = sample_re.search(sl)
131134

132135
if m is not None:
133-
device = str(m.group('device'))
134-
sample = int(m.group('sample'))
136+
try:
137+
device = str(m.group('device'))
138+
sample = int(m.group('sample'))
135139

136-
samples[device] = sample
140+
samples[device] = sample
141+
except (ValueError, OverflowError):
142+
continue
137143

138144
return samples
139145

@@ -144,7 +150,10 @@ def checkWasapiSamples(lines):
144150
for osl in obsSampleLines:
145151
m = samples_re.search(osl)
146152
if m is not None:
147-
obsSample = int(m.group('samples'))
153+
try:
154+
obsSample = int(m.group('samples'))
155+
except (ValueError, OverflowError):
156+
return []
148157
samples = getWasapiSampleRates(lines)
149158

150159
if len(samples) == 0:
@@ -245,14 +254,17 @@ def getWindowsVersion(lines):
245254
if not m:
246255
return
247256

248-
ver = {
249-
"version": m.group("version"),
250-
"build": int(m.group("build")),
251-
"revision": int(m.group("revision")),
252-
"bits": int(m.group("bits")),
253-
"arm": bool(m.group("arm")),
254-
"release": 0
255-
}
257+
try:
258+
ver = {
259+
"version": m.group("version"),
260+
"build": int(m.group("build")),
261+
"revision": int(m.group("revision")),
262+
"bits": int(m.group("bits")),
263+
"arm": bool(m.group("arm")),
264+
"release": 0
265+
}
266+
except (ValueError, OverflowError):
267+
return # Skips the windows version checks
256268

257269
# Older naming/numbering/etc
258270
if ver["version"] in winversions:

0 commit comments

Comments
 (0)