hterm: add sanity check on user font size
If the user accidentally sets the font size to less than 1, the dynamic
calculations result in infinity which causes infinite loops. Make sure
the requested font size is reasonable before we set it.
BUG=b:70646545
Change-Id: I5bbc3b97fc89f32dc6014af7f6f422f24eedbdf1
Reviewed-on: https://chromium-review.googlesource.com/826183
Reviewed-by: Brandon Gilmore <varz@google.com>
Tested-by: Mike Frysinger <vapier@chromium.org>
diff --git a/hterm/js/hterm_terminal.js b/hterm/js/hterm_terminal.js
index 921a443..af3a70b 100644
--- a/hterm/js/hterm_terminal.js
+++ b/hterm/js/hterm_terminal.js
@@ -406,6 +406,12 @@
},
'font-size': function(v) {
+ v = parseInt(v);
+ if (v <= 0) {
+ console.error(`Invalid font size: ${v}`);
+ return;
+ }
+
terminal.setFontSize(v);
},
@@ -763,7 +769,7 @@
* @param {number} px The desired font size, in pixels.
*/
hterm.Terminal.prototype.setFontSize = function(px) {
- if (px === 0)
+ if (px <= 0)
px = this.prefs_.get('font-size');
this.scrollPort_.setFontSize(px);