-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fit() and flat() broken for simple uses of filler= #1517
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Following up, it looks like there were tests for this in Pwntools 3.13, but they were rewritten at some point. Pwntools 3.13 shows:
|
It looks like these are the changes that broke things. @@ -516,14 +520,14 @@ def _fit(pieces, preprocessor, packer, filler):
filler = iters.chain(pad, filler)
# Build output
- out = ''
+ out = b''
for k, v in sorted(pieces.items()):
if k < len(out):
raise ValueError("flat(): data at offset %d overlaps with previous data which ends at offset %d" % (k, len(out)))
# Fill up to offset
while len(out) < k:
- out += filler.next()
+ out += p8(next(filler)) and @@ -647,7 +651,7 @@ def flat(*args, **kwargs):
if length:
if len(out) > length:
raise ValueError("flat(): Arguments does not fit within `length` (= %d) bytes" % length)
- out += ''.join(filler.next() for _ in xrange(length - len(out)))
+ out += b''.join(p8(next(filler)) for _ in range(length - len(out))) Removing the |
It looks like another part of the issue is the internal switch to use |
It looks like something underlying It seems the Python2
Python3With bytes
With a string
|
Honestly this is a Python3 gaffe and I think the easiest way to work around it is to hack the |
@zachriggle Well, just this As for the actual issue, though, So what if:
|
Ultimately the issue comes down to: Python3>>> x = b'a'
>>> x[0] == x
False
>>> x[0]
97 Python2>>> x = b'a'
>>> x[0] == x
True
>>> x[0]
'a' So it looks like iterating over a byte-array is generating ints, in which case the I'll spend some time seeing if I can come up with a more elegant solution or wrapper for this. |
It also occurs to me that using |
The
flat
andfit
routines take an arbitrary iterable for thefiller=
argument. This seems to be broken in recent releases.Pwntools 3.13.0
Pwntools 4.2.0 (works)
Pwntools 4.2.0 (broken, but should work)
The text was updated successfully, but these errors were encountered: