aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Wilm <joe@jwilm.com>2017-12-24 10:00:12 -0800
committerJoe Wilm <joe@jwilm.com>2017-12-24 10:00:12 -0800
commit4fb2109497daddcc2f2f855f23073a4aa699463a (patch)
tree6d844cda78658acab016c49612f165d1c2374cfb
parent793b5cc3a9e16d25a3a623f0a00517da3b04c0ea (diff)
downloadalacritty-4fb2109497daddcc2f2f855f23073a4aa699463a.tar.gz
alacritty-4fb2109497daddcc2f2f855f23073a4aa699463a.zip
Fix stack overflow with too large glyphs
This resolves the remaining issue of #842.
-rw-r--r--src/renderer/mod.rs22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs
index afc4da97..318a1835 100644
--- a/src/renderer/mod.rs
+++ b/src/renderer/mod.rs
@@ -877,7 +877,7 @@ fn load_glyph(
// the unwrap.
match atlas[*current_atlas].insert(rasterized, active_tex) {
Ok(glyph) => glyph,
- Err(_) => {
+ Err(AtlasInsertError::Full) => {
*current_atlas += 1;
if *current_atlas == atlas.len() {
let new = Atlas::new(ATLAS_SIZE);
@@ -886,6 +886,19 @@ fn load_glyph(
}
load_glyph(active_tex, atlas, current_atlas, rasterized)
}
+ Err(AtlasInsertError::GlyphTooLarge) => {
+ Glyph {
+ tex_id: atlas[*current_atlas].id,
+ top: 0.0,
+ left: 0.0,
+ width: 0.0,
+ height: 0.0,
+ uv_bot: 0.0,
+ uv_left: 0.0,
+ uv_width: 0.0,
+ uv_height: 0.0,
+ }
+ }
}
}
@@ -1286,6 +1299,9 @@ struct Atlas {
enum AtlasInsertError {
/// Texture atlas is full
Full,
+
+ /// The glyph cannot fit within a single texture
+ GlyphTooLarge,
}
impl Atlas {
@@ -1337,6 +1353,10 @@ impl Atlas {
active_tex: &mut u32)
-> Result<Glyph, AtlasInsertError>
{
+ if glyph.width > self.width || glyph.height > self.height {
+ return Err(AtlasInsertError::GlyphTooLarge);
+ }
+
// If there's not enough room in current row, go onto next one
if !self.room_in_row(glyph) {
self.advance_row()?;