diff --git a/Userland/Applications/FontEditor/main.cpp b/Userland/Applications/FontEditor/main.cpp index 7055b49708..db91ce1c51 100644 --- a/Userland/Applications/FontEditor/main.cpp +++ b/Userland/Applications/FontEditor/main.cpp @@ -80,7 +80,13 @@ int main(int argc, char** argv) path = "/tmp/saved.font"; edited_font = static_ptr_cast(Gfx::FontDatabase::default_font().clone()); } else { - edited_font = static_ptr_cast(Gfx::BitmapFont::load_from_file(path)->clone()); + auto bitmap_font = Gfx::BitmapFont::load_from_file(path); + if (!bitmap_font) { + String message = String::formatted("Couldn't load font: {}\n", path); + GUI::MessageBox::show(nullptr, message, "Font Editor", GUI::MessageBox::Type::Error); + return 1; + } + edited_font = static_ptr_cast(bitmap_font->clone()); if (!edited_font) { String message = String::formatted("Couldn't load font: {}\n", path); GUI::MessageBox::show(nullptr, message, "Font Editor", GUI::MessageBox::Type::Error); @@ -112,7 +118,13 @@ int main(int argc, char** argv) if (!open_path.has_value()) return; - RefPtr new_font = static_ptr_cast(Gfx::BitmapFont::load_from_file(open_path.value())->clone()); + auto bitmap_font = Gfx::BitmapFont::load_from_file(open_path.value()); + if (!bitmap_font) { + String message = String::formatted("Couldn't load font: {}\n", open_path.value()); + GUI::MessageBox::show(window, message, "Font Editor", GUI::MessageBox::Type::Error); + return; + } + RefPtr new_font = static_ptr_cast(bitmap_font->clone()); if (!new_font) { String message = String::formatted("Couldn't load font: {}\n", open_path.value()); GUI::MessageBox::show(window, message, "Font Editor", GUI::MessageBox::Type::Error); diff --git a/Userland/Applications/TextEditor/TextEditorWidget.cpp b/Userland/Applications/TextEditor/TextEditorWidget.cpp index 071076e9f0..09a946562f 100644 --- a/Userland/Applications/TextEditor/TextEditorWidget.cpp +++ b/Userland/Applications/TextEditor/TextEditorWidget.cpp @@ -639,6 +639,11 @@ bool TextEditorWidget::open_file(const String& path) return false; } + if (file->is_device()) { + GUI::MessageBox::show(window(), String::formatted("Opening \"{}\" failed: Can't open device files", path), "Error", GUI::MessageBox::Type::Error); + return false; + } + m_editor->set_text(file->read_all()); m_document_dirty = false; m_document_opening = true; diff --git a/Userland/DevTools/Playground/main.cpp b/Userland/DevTools/Playground/main.cpp index a542caa53f..592fd31526 100644 --- a/Userland/DevTools/Playground/main.cpp +++ b/Userland/DevTools/Playground/main.cpp @@ -139,6 +139,10 @@ int main(int argc, char** argv) GUI::MessageBox::show(window, String::formatted("Opening \"{}\" failed: {}", path, strerror(errno)), "Error", GUI::MessageBox::Type::Error); return 1; } + if (file->is_device()) { + GUI::MessageBox::show(window, String::formatted("Opening \"{}\" failed: Can't open device files", path), "Error", GUI::MessageBox::Type::Error); + return 1; + } editor.set_text(file->read_all()); } @@ -164,6 +168,11 @@ int main(int argc, char** argv) return; } + if (file->is_device()) { + GUI::MessageBox::show(window, String::formatted("Opening \"{}\" failed: Can't open device files", open_path.value()), "Error", GUI::MessageBox::Type::Error); + return; + } + editor.set_text(file->read_all()); editor.set_focus(true); })); diff --git a/Userland/Libraries/LibGfx/BitmapFont.cpp b/Userland/Libraries/LibGfx/BitmapFont.cpp index b26db96c15..376525064b 100644 --- a/Userland/Libraries/LibGfx/BitmapFont.cpp +++ b/Userland/Libraries/LibGfx/BitmapFont.cpp @@ -172,6 +172,9 @@ size_t BitmapFont::glyph_count_by_type(FontTypes type) RefPtr BitmapFont::load_from_file(const StringView& path) { + if (Core::File::is_device(path)) + return nullptr; + auto file_or_error = MappedFile::map(path); if (file_or_error.is_error()) return nullptr;