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

Skip to content

Commit 88d8494

Browse files
committed
Implementation for an Issue #307
1 parent eb23b1b commit 88d8494

3 files changed

Lines changed: 40 additions & 6 deletions

File tree

lib/core/bigarray.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ def append(self, value):
4040
self.chunks[-1] = filename
4141
self.chunks.append([])
4242

43+
def extend(self, value):
44+
for _ in value:
45+
self.append(_)
46+
4347
def pop(self):
4448
if len(self.chunks[-1]) < 1:
4549
self.chunks.pop()

lib/techniques/error/use.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,8 @@ def errorUse(expression, dump=False):
357357
threadData.shared.limits = iter(xrange(startLimit, stopLimit))
358358
numThreads = min(conf.threads, (stopLimit - startLimit))
359359
threadData.shared.outputs = BigArray()
360+
threadData.shared.buffered = []
361+
threadData.shared.lastFlushed = startLimit - 1
360362

361363
if kb.dumpTable and (len(expressionFieldsList) < (stopLimit - startLimit) > CHECK_ZERO_COLUMNS_THRESHOLD):
362364
for field in expressionFieldsList:
@@ -392,7 +394,15 @@ def errorThread():
392394
output = output[0]
393395

394396
with kb.locks.outputs:
395-
threadData.shared.outputs.append(output)
397+
index = None
398+
for index in xrange(len(threadData.shared.buffered)):
399+
if threadData.shared.buffered[index][0] >= num:
400+
break
401+
threadData.shared.buffered.insert(index or 0, (num, output))
402+
while threadData.shared.buffered and threadData.shared.lastFlushed + 1 == threadData.shared.buffered[0][0]:
403+
threadData.shared.lastFlushed += 1
404+
threadData.shared.outputs.append(threadData.shared.buffered[0][1])
405+
del threadData.shared.buffered[0]
396406

397407
runThreads(numThreads, errorThread)
398408

@@ -403,6 +413,7 @@ def errorThread():
403413
logger.warn(warnMsg)
404414

405415
finally:
416+
threadData.shared.outputs.extend(_[1] for _ in sorted(threadData.shared.buffered))
406417
outputs = threadData.shared.outputs
407418
kb.suppressResumeInfo = False
408419

lib/techniques/union/use.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,8 @@ def unionUse(expression, unpack=True, dump=False):
274274
threadData.shared.limits = iter(xrange(startLimit, stopLimit))
275275
numThreads = min(conf.threads, (stopLimit - startLimit))
276276
threadData.shared.value = BigArray()
277+
threadData.shared.buffered = []
278+
threadData.shared.lastFlushed = startLimit - 1
277279

278280
if stopLimit > TURN_OFF_RESUME_INFO_LIMIT:
279281
kb.suppressResumeInfo = True
@@ -306,14 +308,28 @@ def unionThread():
306308
break
307309

308310
if output:
309-
if all(map(lambda x: x in output, [kb.chars.start, kb.chars.stop])):
311+
if all(map(lambda _: _ in output, (kb.chars.start, kb.chars.stop))):
310312
items = parseUnionPage(output)
311-
if isNoneValue(items):
312-
continue
313+
313314
with kb.locks.value:
314-
for item in arrayizeValue(items):
315-
threadData.shared.value.append(item)
315+
index = None
316+
for index in xrange(len(threadData.shared.buffered)):
317+
if threadData.shared.buffered[index][0] >= num:
318+
break
319+
threadData.shared.buffered.insert(index or 0, (num, items))
320+
while threadData.shared.buffered and threadData.shared.lastFlushed + 1 == threadData.shared.buffered[0][0]:
321+
threadData.shared.lastFlushed += 1
322+
_ = threadData.shared.buffered[0][1]
323+
if not isNoneValue(_):
324+
threadData.shared.value.extend(arrayizeValue(_))
325+
del threadData.shared.buffered[0]
316326
else:
327+
with kb.locks.value:
328+
index = None
329+
for index in xrange(len(threadData.shared.buffered)):
330+
if threadData.shared.buffered[index][0] >= num:
331+
break
332+
threadData.shared.buffered.insert(index or 0, (num, None))
317333
items = output.replace(kb.chars.start, "").replace(kb.chars.stop, "").split(kb.chars.delimiter)
318334

319335
if conf.verbose == 1 and not (threadData.resumed and kb.suppressResumeInfo):
@@ -337,6 +353,9 @@ def unionThread():
337353
logger.warn(warnMsg)
338354

339355
finally:
356+
for _ in sorted(threadData.shared.buffered):
357+
if not isNoneValue(_[1]):
358+
threadData.shared.value.extend(arrayizeValue(_[1]))
340359
value = threadData.shared.value
341360
kb.suppressResumeInfo = False
342361

0 commit comments

Comments
 (0)