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:
Jaime van Kessel 2020-02-27 16:30:35 +01:00
parent d7102729f1
commit 3958d85a9a
No known key found for this signature in database
GPG key ID: 3710727397403C91

View file

@ -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,9 +25,7 @@ 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()
uncompressed_gcode = gzip.decompress(file_data).decode("utf-8")
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")
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)