mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-08 07:27:29 -06:00
Revert "Prevent zip bombs in the g-codegz reader"
This reverts commit 27777c759c
.
Resource isn't available on windows, so the solution won't do what needs to be done
This commit is contained in:
parent
d7102729f1
commit
3958d85a9a
1 changed files with 1 additions and 17 deletions
|
@ -7,20 +7,6 @@ from UM.Mesh.MeshReader import MeshReader #The class we're extending/implementin
|
||||||
from UM.MimeTypeDatabase import MimeTypeDatabase, MimeType #To add the .gcode.gz files to the MIME type database.
|
from UM.MimeTypeDatabase import MimeTypeDatabase, MimeType #To add the .gcode.gz files to the MIME type database.
|
||||||
from UM.PluginRegistry import PluginRegistry
|
from UM.PluginRegistry import PluginRegistry
|
||||||
|
|
||||||
import contextlib
|
|
||||||
import resource
|
|
||||||
|
|
||||||
|
|
||||||
@contextlib.contextmanager
|
|
||||||
def limit(limit, type=resource.RLIMIT_AS):
|
|
||||||
soft_limit, hard_limit = resource.getrlimit(type)
|
|
||||||
resource.setrlimit(type, (limit, hard_limit)) # set soft limit
|
|
||||||
try:
|
|
||||||
yield
|
|
||||||
finally:
|
|
||||||
resource.setrlimit(type, (soft_limit, hard_limit)) # restore
|
|
||||||
|
|
||||||
|
|
||||||
## A file reader that reads gzipped g-code.
|
## A file reader that reads gzipped g-code.
|
||||||
#
|
#
|
||||||
# If you're zipping g-code, you might as well use gzip!
|
# If you're zipping g-code, you might as well use gzip!
|
||||||
|
@ -39,8 +25,6 @@ class GCodeGzReader(MeshReader):
|
||||||
def _read(self, file_name):
|
def _read(self, file_name):
|
||||||
with open(file_name, "rb") as file:
|
with open(file_name, "rb") as file:
|
||||||
file_data = file.read()
|
file_data = file.read()
|
||||||
|
|
||||||
with limit(1 << 30): # Prevent a gzip bomb (by setting the max size to 1 gig)
|
|
||||||
uncompressed_gcode = gzip.decompress(file_data).decode("utf-8")
|
uncompressed_gcode = gzip.decompress(file_data).decode("utf-8")
|
||||||
PluginRegistry.getInstance().getPluginObject("GCodeReader").preReadFromStream(uncompressed_gcode)
|
PluginRegistry.getInstance().getPluginObject("GCodeReader").preReadFromStream(uncompressed_gcode)
|
||||||
result = PluginRegistry.getInstance().getPluginObject("GCodeReader").readFromStream(uncompressed_gcode, file_name)
|
result = PluginRegistry.getInstance().getPluginObject("GCodeReader").readFromStream(uncompressed_gcode, file_name)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue