"ERROR interpreting JPEG image file( invalid JPEG file structure :SOS before SOF)" 是什么意思?

What does "ERROR interpreting JPEG image file( invalid JPEG file structure :SOS before SOF)" mean?

我正在尝试从 .raw 文件恢复 JPG,当我尝试从我的程序输出中打开“.jpg”时,它给出了那个错误,或者它说一些奇怪的十六进制并说它是 JPEG 不支持的标记类型(但它说它是 jpg!)。我做错了什么?

     *
 * Recovers JPEGs from a forensic image.
 */

 //0xff 0xd8 0xff 0xe0
 //0xff 0xd8 0xff 0xe1

#define BLOCK 512
#define START1END 0xe0
#define START2END 0xe1

#include <stdio.h>
#include <cs50.h>
#include <stdlib.h>
#include <stdint.h>


//sets the begins or jpgs
uint8_t checkjpg1[4] = {0xff, 0xd8, 0xff, 0xe0};
uint8_t checkjpg2[4] = {0xff, 0xd8, 0xff, 0xe1};

//making variables
int found = 0; 
char title[BLOCK];
FILE* img;
int ifopen = 1;


int main(int argc, char* argv[])
{
    //opening file
    FILE* inptr = fopen("card.raw", "r");
    //checking if file opening failed
    if (inptr == NULL)
    {
        return 2;
    }

    //making buffer
    unsigned char buffer[BLOCK];

    //going through the file
    while(fread(&buffer,sizeof(char),BLOCK,inptr) == BLOCK)
    {
         //checking if begin == the possible begin of jpg    
         if ((buffer[0] == checkjpg1[0] && buffer[1] == checkjpg1[1] && buffer[2] == checkjpg1[2]) && 
         (buffer[3] == checkjpg1[3] || buffer[3] == checkjpg2[3]))
         {
            //if a jpg is not open
            if (ifopen == 1)
            {
                //make one
                found+=1;
                sprintf(title,"00%d.jpg",found);
                img = fopen(title,"a");
                if(buffer[3] == checkjpg1[3])
                {
                    fwrite(&checkjpg1,sizeof(char),4,img);
                }

            }
            else//else
            {
                //end the one and open new one
                fclose(img);
                found +=1;
                sprintf(title,"00%d.jpg",found);
                img = fopen(title,"a");
                if(buffer[3] == checkjpg1[3])
                {
                    fwrite(&checkjpg2,sizeof(char),4,img);
                }
            }
         }
         else if (img != NULL)
         {
            fwrite(buffer,sizeof(char),BLOCK,img);
         }
     }

    fclose(inptr);
}

帧起始 (SOF) 市场定义了图像的结构。扫描开始标记包含压缩图像数据。您需要知道图像的大小 (SOF) 才能扩展压缩数据 (SOS)。

听起来您的流缺少 SOF 标记。