midstar / pycstruct

A python library for reading and writing binary data similar to what is done in C language structs
MIT License
24 stars 4 forks source link

pycstruct fails when run by multiple users #44

Closed thomask77 closed 8 months ago

thomask77 commented 8 months ago

Hi!

pystruct always generates the same cache file name in /tmp when the input files are the same:

This breaks when multiple users on the same machine try to run pycstruct because of missing write permissions:

...
subprocess.CalledProcessError: Command '['castxml', 'Source/fpga_regs.h', '--castxml-gccxml', '-o', '/tmp/0dfc346420.xml']' returned non-zero exit status 1.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
...
    _run_castxml(
  File "/home/dleesing/Code/click/venv/lib/python3.11/site-packages/pycstruct/cparser.py", line 62, in _run_castxml
    raise RuntimeError(
RuntimeError: Unable to run:
castxml Source/fpga_regs.h --castxml-gccxml -o /tmp/0dfc346420.xml

Output:
error: unable to open output file '/tmp/0dfc346420.xml': 'Operation not permitted'
1 error generated.

pycstruct should at least include the current user name in the hash. And it should probably use random tmp file names if use_cached is False.

thomask77 commented 8 months ago

Follow up:

pycstruct also doesn't hash the input file contents!

So if the files change, pycstruct will yield wrong results when using the cache.

midstar commented 8 months ago

Hi!

Thank you for your feedback! I agree that a the user name should be used in the file name to avoid collisions with other users.

I think it would be quite complex to generate a hash based on contents since files that you parse might include other files (read by castxml) which pycstruct don't know about. You should avoid using use_cached unless you have a very stable data format that you know will not change.

midstar commented 8 months ago

Multi-user bug fixed in version 0.12.2.