private void validateAndIgnoreHeader() throws IOException {
    readIntoBlock(0 /* offset */, 6 /* length */);
    boolean valid =
        'G' == (char) block[0]
            && 'I' == (char) block[1]
            && 'F' == (char) block[2]
            && '8' == (char) block[3]
            && ('7' == (char) block[4] || '9' == (char) block[4])
            && 'a' == (char) block[5];
    if (!valid) {
      throw new IOException("Illegal header for gif");
    }

    skipAndWriteBytes(4); // width, height

    int fields = readAndWriteNextByte();
    boolean hasGlobalColorTable = (fields & 0x80) != 0;
    int globalColorTableSize = 2 << (fields & 7);

    skipAndWriteBytes(2); // bgc index, aspect ratio

    if (hasGlobalColorTable) {
      ignoreColorTable(globalColorTableSize);
    }
  }
@param is InputStream to decode
@param os OutputStream to write fixed version of gif, if needed. (optional)
animated-gif-lite/src/main/java/com/facebook/animated/giflite/decoder/GifMetadataDecoder.java