title: Should I expect JPEG SOI marker at very beginning of the data stream?
body: <p>... or should I go deeper into the data stream looking for <code>0xFF 0xD8</code> sequence?</p>
  
  <p>From <a href="https://stackoverflow.com/questions/5413022/is-the-2nd-and-3rd-byte-of-a-jpeg-image-always-the-app0-or-app1-marker">this Q</a>, I've learned what APPn does not have to follow SOI immediately. Are there specification compliant JPEG cases where SOI position != beginning of the stream?</p>
  
  <hr>
  
  <p>A quote from the specification (Annex B, § 1.1.2):</p>
  
  <blockquote>
    <p>Markers serve to identify the various structural parts of the
    compressed data formats. Most markers start marker segments containing
    a related group of parameters; some markers stand alone. All markers
    are assigned two-byte codes: an X’FF’ byte followed by a byte which is
    not equal to 0 or X’FF’ (see Table B.1). Any marker may optionally be
    preceded by any number of fill bytes, which are bytes assigned code
    X’FF’.</p>
  </blockquote>