<commit_before>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <setjmp.h>
#include <string.h>

#include "jpeglib.h"

#include "meh.h"

struct error_mgr{
	struct jpeg_error_mgr pub;
	jmp_buf jmp_buffer;
};

struct jpeg_t{
	struct image img;
	FILE *f;
	struct jpeg_decompress_struct cinfo;
	struct error_mgr jerr;
};

static void error_exit(j_common_ptr cinfo){
	(void) cinfo;
	printf("\nerror!\n");
	exit(1);
}

static struct image *jpeg_open(FILE *f){
	struct jpeg_t *j;

	rewind(f);
	if(getc(f) != 0xff || getc(f) != 0xd8)
		return NULL;

	j = malloc(sizeof(struct jpeg_t));
	j->f = f;
	rewind(f);

	j->cinfo.err = jpeg_std_error(&j->jerr.pub);
	j->jerr.pub.error_exit = error_exit;

	jpeg_create_decompress(&j->cinfo);
	jpeg_stdio_src(&j->cinfo, f);
	jpeg_read_header(&j->cinfo, TRUE);

	/* parameters */
	j->cinfo.do_fancy_upsampling = 0;
	j->cinfo.do_block_smoothing = 0;
	j->cinfo.quantize_colors = 0;
	j->cinfo.dct_method = JDCT_FASTEST;

	jpeg_calc_output_dimensions(&j->cinfo);

	j->img.bufwidth = j->cinfo.output_width;
	j->img.bufheight = j->cinfo.output_height;

	return (struct image *)j;
}

static int jpeg_read(struct image *img){
	struct jpeg_t *j = (struct jpeg_t *)img;
	unsigned int row_stride;
	int a = 0, b;
	unsigned int x, y;

	row_stride = j->cinfo.output_width * j->cinfo.output_components;

	jpeg_start_decompress(&j->cinfo);

	unsigned char *buf = img->buf;
<commit_msg>no longer exit for unreadable jpeg's<commit_after>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <setjmp.h>
#include <string.h>

#include "jpeglib.h"

#include "meh.h"

struct error_mgr{
	struct jpeg_error_mgr pub;
	jmp_buf jmp_buffer;
};

struct jpeg_t{
	struct image img;
	FILE *f;
	struct jpeg_decompress_struct cinfo;
	struct error_mgr jerr;
};

static void error_exit(j_common_ptr cinfo){
	(void) cinfo;
	printf("\nerror!\n");
	exit(1);
}

static void error_longjmp(j_common_ptr cinfo){
    struct error_mgr *myerr = (struct error_mgr *)cinfo->err;
    (*cinfo->err->output_message)(cinfo);
    longjmp(myerr->jmp_buffer, 1);
}

static struct image *jpeg_open(FILE *f){
	struct jpeg_t *j;

	rewind(f);
	if(getc(f) != 0xff || getc(f) != 0xd8)
		return NULL;

	j = malloc(sizeof(struct jpeg_t));
	j->f = f;
	rewind(f);

	j->cinfo.err = jpeg_std_error(&j->jerr.pub);
	j->jerr.pub.error_exit = error_longjmp;
	if (setjmp(j->jerr.jmp_buffer)) {
		return NULL;
	}

	jpeg_create_decompress(&j->cinfo);
	jpeg_stdio_src(&j->cinfo, f);
	jpeg_read_header(&j->cinfo, TRUE);

	/* parameters */
	j->cinfo.do_fancy_upsampling = 0;
	j->cinfo.do_block_smoothing = 0;
	j->cinfo.quantize_colors = 0;
	j->cinfo.dct_method = JDCT_FASTEST;

	jpeg_calc_output_dimensions(&j->cinfo);

	j->img.bufwidth = j->cinfo.output_width;
	j->img.bufheight = j->cinfo.output_height;

	j->jerr.pub.error_exit = error_exit;
	return (struct image *)j;
}

static int jpeg_read(struct image *img){
	struct jpeg_t *j = (struct jpeg_t *)img;
	unsigned int row_stride;
	int a = 0, b;
	unsigned int x, y;

	j->jerr.pub.error_exit = error_longjmp;
	if(setjmp(j->jerr.jmp_buffer)){
		return 1; /* ERROR */
	}

	row_stride = j->cinfo.output_width * j->cinfo.output_components;

	jpeg_start_decompress(&j->cinfo);

	unsigned char *buf = img->buf;

{'fraction_non_alphanumeric': 0.15700185070943862, 'fraction_numerical': 0.005552128315854411, 'mean_word_length': 4.669580419580419, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1136794', 'n_tokens_mistral': 1448, 'n_tokens_neox': 1388, 'n_words': 272}