Gallopsled / Gallopsled/pwntools
[Bug?] FileStructure.struntil one byte shorter for no apparent reason?
- Dominant language
- Python
- Stars
- 13.7k
- Forks
- 1.9k
- Avg merge
- 6d 23h
- Merged PRs (30d)
- 3
Description
The function `FileStructure.struntil` returns one byte less for no apparent reason. For example, when I request `fp.struntil("flags")` I expect to get all 8 bytes of the flags struct.
# Tested in the pwntools:stable dockercontainer
```
pwntools@541d39158471:/$ python
Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pwn import *
>>> context.clear(arch="amd64")
>>> fp = FileStructure()
>>> payload = fp.struntil("flags")
>>> len(payload)
7
```
-> I only got 7 bytes
## Reason
In `pwnlib/filepointer.py` the last byte gets truncated
```
def struntil(self,v):
[...]
return structure[:-1]
```
## Proposed fix
Either remove the `[:-1]` or write it in the documentation why the function is supposed to behave this way.
Contributor guide
Research direction
Start in pwnlib/filepointer.py at FileStructure.struntil and run the provided Python reproduction with the amd64 context to confirm the returned length. Check whether the final byte is intentionally removed; done means the function's behavior matches its intended contract and is covered by an appropriate test or documented clearly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100