Skip to content

[Bug?] FileStructure.struntil one byte shorter for no apparent reason? #2403

@goreil

Description

@goreil

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions