Problem parsing a buffer containing data from JPEG image
Sorry if this is not the right place to ask this, but I did not find how to create issues on the https://github.com/kaitai-io/kaitai_struct_formats repo

The thing is that I think that probably the JPEG parser present on the gallery is not working well.
I need to parse a buffer which is contained inside another buffer with any kind of content, i.e., the JPEG file is embedded, and I have to be able to find where it starts and ends. It is important to note that I have the same problem even with pure jpeg files. Btw, I'm working in python

For this task, the flow is more or less the following:

- find JPEG signature in the bigger buffer
- if signature found, try to parse content of the buffer with the jpeg module

so far, so good.

Looking at the segments read by the module, I realized that the last segment is not the EOI segment (End of Image), but the SOS segment (Start of Scan).
So, in one hand, the parser doesn't recognize where the image ends, and in the other hand, all the bytes from the buffer are consumed and loaded into the image_data attribute of the segment object.

Any idea why is this happening? Or am I misunderstanding something? I think it probably has to do with the declaration of this format, but I'm not sure.

I could do this with GIF and PNG images by reading the rest of the bytes from the buffer (lets say the "rest"), and getting a sub-buffer from the signature until the position where the "rest" starts. But as I said before, the JPEG parser consumes all the bytes, so there are no more bytes to read after parsing the buffer.