Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d54ec88

Browse files
committed
Adding compression to BigArray mechanism (to save disk space on big dumps)
1 parent f210d66 commit d54ec88

3 files changed

Lines changed: 14 additions & 9 deletions

File tree

lib/core/bigarray.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@
1414
import os
1515
import sys
1616
import tempfile
17+
import zlib
1718

1819
from lib.core.enums import MKSTEMP_PREFIX
1920
from lib.core.exception import SqlmapSystemException
2021
from lib.core.settings import BIGARRAY_CHUNK_SIZE
22+
from lib.core.settings import BIGARRAY_COMPRESS_LEVEL
2123

2224
DEFAULT_SIZE_OF = sys.getsizeof(object())
2325

@@ -80,8 +82,8 @@ def pop(self):
8082
if len(self.chunks[-1]) < 1:
8183
self.chunks.pop()
8284
try:
83-
with open(self.chunks[-1], "rb") as fp:
84-
self.chunks[-1] = pickle.load(fp)
85+
with open(self.chunks[-1], "rb") as f:
86+
self.chunks[-1] = pickle.loads(zlib.decompress(f.read()))
8587
except IOError, ex:
8688
errMsg = "exception occurred while retrieving data "
8789
errMsg += "from a temporary file ('%s')" % ex.message
@@ -101,8 +103,8 @@ def _dump(self, chunk):
101103
handle, filename = tempfile.mkstemp(prefix=MKSTEMP_PREFIX.BIG_ARRAY)
102104
self.filenames.add(filename)
103105
os.close(handle)
104-
with open(filename, "w+b") as fp:
105-
pickle.dump(chunk, fp, pickle.HIGHEST_PROTOCOL)
106+
with open(filename, "w+b") as f:
107+
f.write(zlib.compress(pickle.dumps(chunk, pickle.HIGHEST_PROTOCOL), BIGARRAY_COMPRESS_LEVEL))
106108
return filename
107109
except (OSError, IOError), ex:
108110
errMsg = "exception occurred while storing data "
@@ -119,8 +121,8 @@ def _checkcache(self, index):
119121

120122
if not (self.cache and self.cache.index == index):
121123
try:
122-
with open(self.chunks[index], "rb") as fp:
123-
self.cache = Cache(index, pickle.load(fp), False)
124+
with open(self.chunks[index], "rb") as f:
125+
self.cache = Cache(index, pickle.loads(zlib.decompress(f.read())), False)
124126
except IOError, ex:
125127
errMsg = "exception occurred while retrieving data "
126128
errMsg += "from a temporary file ('%s')" % ex.message

lib/core/settings.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from lib.core.enums import OS
2020

2121
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
22-
VERSION = "1.1.11.21"
22+
VERSION = "1.1.11.22"
2323
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
2424
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
2525
VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)
@@ -520,6 +520,9 @@
520520
# Approximate chunk length (in bytes) used by BigArray objects (only last chunk and cached one are held in memory)
521521
BIGARRAY_CHUNK_SIZE = 1024 * 1024
522522

523+
# Compress (zlib) level used for storing BigArray chunks to disk (0-9)
524+
BIGARRAY_COMPRESS_LEVEL = 9
525+
523526
# Maximum number of socket pre-connects
524527
SOCKET_PRE_CONNECT_QUEUE_SIZE = 3
525528

txt/checksum.md5

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ f96467fc5cd1d87f52dd7966c8ae6e79 extra/shutils/regressiontest.py
2626
d2cdb9e832e18a81e936ca3348144b16 lib/controller/handler.py
2727
5fb9aaf874daa47ea2b672a22740e56b lib/controller/__init__.py
2828
fd69e56ce20a5a49ce10a7a745022378 lib/core/agent.py
29-
d55b4b58019d6dbfddd40ec919f9f172 lib/core/bigarray.py
29+
8d9d771f7e67582c56a96a8d0ccbe4fc lib/core/bigarray.py
3030
16b63aed575a43c1d406df30a9b22afe lib/core/common.py
3131
54326d3a690f8b26fe5a5da1a589b369 lib/core/convert.py
3232
90b1b08368ac8a859300e6fa6a8c796e lib/core/data.py
@@ -46,7 +46,7 @@ e1c000db9be27f973569b1a430629037 lib/core/option.py
4646
760d9df2a27ded29109b390ab202e72d lib/core/replication.py
4747
a2466b62e67f8b31736bac4dac590e51 lib/core/revision.py
4848
02d4762140a72fd44668d3dab5eabda9 lib/core/session.py
49-
915cf4eeb4fefcb6ebb8c10cd3c50468 lib/core/settings.py
49+
5ca78784a48256f3b8a7bc98b9ec1978 lib/core/settings.py
5050
35bffbad762eb9e03db9e93b1c991103 lib/core/shell.py
5151
a59ec28371ae067a6fdd8f810edbee3d lib/core/subprocessng.py
5252
d5a04d672a18f78deb2839c3745ff83c lib/core/target.py

0 commit comments

Comments
 (0)