Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
flow3r firmware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
flow3r
flow3r firmware
Commits
e39acdcf
Commit
e39acdcf
authored
1 year ago
by
ave
Committed by
ave
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
apps/fil3s: Limit filesize to 10KiB
parent
0b6bcb1d
No related branches found
No related tags found
1 merge request
!638
apps/fil3s: Limit filesize to 10KiB
Pipeline
#9533
passed
1 year ago
Stage: check
Stage: build
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
python_payload/apps/fil3s/reader.py
+14
-4
14 additions, 4 deletions
python_payload/apps/fil3s/reader.py
with
14 additions
and
4 deletions
python_payload/apps/fil3s/reader.py
+
14
−
4
View file @
e39acdcf
import
os
import
gc
import
media
from
ctx
import
Context
...
...
@@ -21,6 +22,7 @@ class Reader(ActionView):
has_error
:
bool
=
False
is_media
:
bool
=
False
content
:
str
error_message
:
str
viewport_offset
=
(
0.0
,
0.0
)
zoom_enabled
=
False
...
...
@@ -34,6 +36,7 @@ class Reader(ActionView):
update_path
:
Callable
[[
str
],
None
],
)
->
None
:
super
().
__init__
()
gc
.
collect
()
self
.
scroll_x
=
CapScrollController
()
self
.
scroll_y
=
CapScrollController
()
...
...
@@ -158,9 +161,9 @@ class Reader(ActionView):
ctx
.
move_to
(
0
,
-
10
)
ctx
.
text
(
"
Can
'
t read file
"
)
if
not
self
.
is_media
:
if
not
self
.
is_media
and
self
.
error_message
:
ctx
.
move_to
(
0
,
20
)
ctx
.
text
(
"
(Not UTF-8?)
"
)
ctx
.
text
(
self
.
error_message
)
ctx
.
restore
()
...
...
@@ -175,7 +178,7 @@ class Reader(ActionView):
else
:
ctx
.
font_size
=
16
ctx
.
move_to
(
self
.
viewport_offset
[
0
],
self
.
viewport_offset
[
1
])
ctx
.
text
(
f
"
{
self
.
content
}
"
)
ctx
.
text
(
self
.
content
)
ctx
.
restore
()
def
_draw_media
(
self
,
ctx
:
Context
)
->
None
:
...
...
@@ -196,16 +199,22 @@ class Reader(ActionView):
try
:
with
open
(
self
.
path
,
"
r
"
,
encoding
=
"
utf-8
"
)
as
f
:
self
.
content
=
f
.
read
()
except
:
except
Exception
:
self
.
has_error
=
True
def
_check_file
(
self
)
->
bool
:
# Disallow files above 10KiB to avoid crashes
if
os
.
stat
(
self
.
path
)[
6
]
>
10
*
1024
:
self
.
error_message
=
"
(Too big, >10KiB)
"
return
False
# Dumb way to check if file is UTF-8 only
try
:
with
open
(
self
.
path
,
"
r
"
,
encoding
=
"
utf-8
"
)
as
f
:
f
.
read
(
100
)
return
True
except
UnicodeError
:
self
.
error_message
=
"
(Not UTF-8?)
"
return
False
def
_is_media
(
self
)
->
bool
:
...
...
@@ -215,5 +224,6 @@ class Reader(ActionView):
return
False
def
on_exit
(
self
):
gc
.
collect
()
if
self
.
is_media
:
media
.
stop
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment