diff --git a/pwnlib/util/packing.py b/pwnlib/util/packing.py index 319948c3f..ad73364ca 100644 --- a/pwnlib/util/packing.py +++ b/pwnlib/util/packing.py @@ -576,14 +576,14 @@ def fit(pieces, **kwargs): >>> fit({12: 0x41414141, ... 24: 'Hello', ... }) - 'aaaabaaacaaaAAAAdaaaeaaaHello' + 'aaaabaaacaaaAAAAeaaafaaaHello' >>> fit({'caaa': ''}) 'aaaabaaa' >>> fit({12: 'XXXX'}, filler = 'AB', length = 20) 'ABABABABABABXXXXABAB' >>> fit({ 8: [0x41414141, 0x42424242], ... 20: 'CCCC'}) - 'aaaabaaaAAAABBBBcaaaCCCC' + 'aaaabaaaAAAABBBBeaaaCCCC' """ # HACK: To avoid circular imports we need to delay the import of `cyclic` @@ -627,6 +627,11 @@ def fit(pieces, **kwargs): out.append(filler.next()) v = _flat([v], preprocessor, packer) l = k + len(v) + + # consume the filler for each byte of actual data + for i in range(len(out), l): + filler.next() + out[k:l] = v # truncate/pad output