Skip to content

Commit

Permalink
checks: Guard float/int conversions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Penwy authored and RytoEX committed Jun 8, 2024
1 parent d5692b0 commit 077c1a4
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 43 deletions.
5 changes: 4 additions & 1 deletion checks/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ def checkAudioBuffering(lines):
for i in buffering:
m = audiobuf_re.search(i)
if m:
vals.append(int(m.group("total")))
try:
vals.append(int(m.group("total")))
except (ValueError, OverflowError):
pass

if (max(vals) > 500):
return [LEVEL_WARNING, "High Audio Buffering",
Expand Down
7 changes: 5 additions & 2 deletions checks/encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,11 @@ def checkEncoding(lines):
val = 0
severity = 9000
for drop in drops:
v = float(drop[drop.find("(") + 1: drop.find(")")
].strip('%').replace(",", "."))
try:
v = float(drop[drop.find("(") + 1: drop.find(")")
].strip('%').replace(",", "."))
except (ValueError, OverflowError):
v = 0
if (v > val):
val = v
if (val != 0):
Expand Down
34 changes: 21 additions & 13 deletions checks/graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ def getRenderLag(lines):
val = 0
severity = 9000
for drop in drops:
v = float(drop[drop.find("(") + 1: drop.find(")")
].strip('%').replace(",", "."))
try:
v = float(drop[drop.find("(") + 1: drop.find(")")
].strip('%').replace(",", "."))
except (ValueError, OverflowError):
v = 0
if (v > val):
val = v

Expand Down Expand Up @@ -62,27 +65,32 @@ def checkVideoSettings(lines):
if "video settings reset:" in s:
videoSettings.append(i)
if (len(videoSettings) > 0):
fmt = lines[videoSettings[-1] + 5].split()[-1]
yuv = lines[videoSettings[-1] + 6].split()[-1]
if 'Full' in yuv:
res.append([LEVEL_WARNING, "Wrong YUV Color Range",
"""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"."""])
if (fmt != 'NV12' and fmt != 'P010'):
res.append([LEVEL_CRITICAL, "Wrong Color Format",
"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."])

basex, basey = lines[videoSettings[-1] + 1].split()[-1].split('x')
outx, outy = lines[videoSettings[-1] + 2].split()[-1].split('x')
fps_num, fps_den = lines[videoSettings[-1] + 4].split()[-1].split('/')
fmt = lines[videoSettings[-1] + 5].split()[-1]
yuv = lines[videoSettings[-1] + 6].split()[-1]
baseAspect = float(basex) / float(basey)
outAspect = float(outx) / float(outy)
fps = float(fps_num) / float(fps_den)
try:
baseAspect = float(basex) / float(basey)
outAspect = float(outx) / float(outy)
fps = float(fps_num) / float(fps_den)
except (ValueError, OverflowError):
return res # If fetching the resolution/fps fails, skip those checks

if ((not ((1.77 < baseAspect) and (baseAspect < 1.7787))) or (not ((1.77 < outAspect) and (outAspect < 1.7787)))):
res.append([LEVEL_WARNING, "Non-Standard Aspect Ratio",
"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."])
if (fmt != 'NV12' and fmt != 'P010'):
res.append([LEVEL_CRITICAL, "Wrong Color Format",
"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."])
if (not ((fps == 60) or (fps == 30))):
res.append([LEVEL_WARNING, "Non-Standard Framerate",
"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."])
if (fps >= 144):
res.append([LEVEL_WARNING, "Excessively High Framerate",
"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."])
if 'Full' in yuv:
res.append([LEVEL_WARNING, "Wrong YUV Color Range",
"""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"."""])
return res
11 changes: 7 additions & 4 deletions checks/macos.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,13 @@ def checkMacVer(lines):
return

mv = "macOS %s.%s" % (html.escape(verinfo["major"]), html.escape(verinfo["minor"]))
if (int(verinfo["major"]) <= 10 and "max" in verinfo):
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"]))
mv += " (EOL)"
return [LEVEL_WARNING, mv, msg]
try:
if (int(verinfo["major"]) <= 10 and "max" in verinfo):
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"]))
mv += " (EOL)"
return [LEVEL_WARNING, mv, msg]
except (ValueError, OverflowError):
pass

if "latest" in verinfo:
msg = "You are running %s %s, which is currently supported by Apple and the most recent version of OBS." % (mv, html.escape(verinfo["name"]))
Expand Down
18 changes: 12 additions & 6 deletions checks/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ def checkDrop(lines):
val = 0
severity = 9000
for drop in drops:
v = float(drop[drop.find("(") + 1: drop.find(")")
].strip('%').replace(",", "."))
try:
v = float(drop[drop.find("(") + 1: drop.find(")")
].strip('%').replace(",", "."))
except (ValueError, OverflowError):
v = 0
if (v > val):
val = v
if (val != 0):
Expand Down Expand Up @@ -58,10 +61,13 @@ def checkNICSpeed(lines):
m = nicspeed_re.search(i)
if m:
nic = m.group("nicname")
if m.group("speed"):
speed = int(m.group("speed"))
elif m.group("upspeed"):
speed = int(m.group("upspeed"))
try:
if m.group("speed"):
speed = int(m.group("speed"))
elif m.group("upspeed"):
speed = int(m.group("upspeed"))
except (ValueError, OverflowError):
speed = 1000
if speed < 1000:
if 'GbE' in nic or 'Gigabit' in nic:
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."]
Expand Down
46 changes: 29 additions & 17 deletions checks/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,14 @@ def getMonitorRefreshes(lines):
m = refresh_re.search(rl)

if m is not None:
if m.group("name") is not None:
output = m.group("name").strip() + " (" + str(int(m.group("output_num")) + 1) + ")"
else:
output = "Display " + m.group("output_num")
refresh = float(m.group("refresh"))
try:
if m.group("name") is not None:
output = m.group("name").strip() + " (" + str(int(m.group("output_num")) + 1) + ")"
else:
output = "Display " + m.group("output_num")
refresh = float(m.group("refresh"))
except (ValueError, OverflowError):
continue

refreshes[output] = refresh

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

if m is not None:
device = str(m.group('device'))
sample = int(m.group('sample'))
try:
device = str(m.group('device'))
sample = int(m.group('sample'))

samples[device] = sample
samples[device] = sample
except (ValueError, OverflowError):
continue

return samples

Expand All @@ -144,7 +150,10 @@ def checkWasapiSamples(lines):
for osl in obsSampleLines:
m = samples_re.search(osl)
if m is not None:
obsSample = int(m.group('samples'))
try:
obsSample = int(m.group('samples'))
except (ValueError, OverflowError):
return []
samples = getWasapiSampleRates(lines)

if len(samples) == 0:
Expand Down Expand Up @@ -245,14 +254,17 @@ def getWindowsVersion(lines):
if not m:
return

ver = {
"version": m.group("version"),
"build": int(m.group("build")),
"revision": int(m.group("revision")),
"bits": int(m.group("bits")),
"arm": bool(m.group("arm")),
"release": 0
}
try:
ver = {
"version": m.group("version"),
"build": int(m.group("build")),
"revision": int(m.group("revision")),
"bits": int(m.group("bits")),
"arm": bool(m.group("arm")),
"release": 0
}
except (ValueError, OverflowError):
return # Skips the windows version checks

# Older naming/numbering/etc
if ver["version"] in winversions:
Expand Down

0 comments on commit 077c1a4

Please sign in to comment.