Skip to content

Commit

Permalink
dep/libchdr: Update and fix numerous vulnerabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Oct 25, 2024
1 parent 19ae3be commit 9e5deb8
Show file tree
Hide file tree
Showing 7 changed files with 491 additions and 361 deletions.
8 changes: 5 additions & 3 deletions dep/libchdr/include/libchdr/cdrom.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@

#pragma once

#ifndef __CDROM_H__
#define __CDROM_H__
#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>
#include <stdbool.h>
#include <libchdr/chdconfig.h>

/***************************************************************************
Expand Down Expand Up @@ -55,7 +56,7 @@ enum
};

const char* cdrom_get_subtype_string(uint32_t subtype);
bool cdrom_parse_subtype_string(const char* typestring, uint32_t* subtype, uint32_t* subsize);
int cdrom_parse_subtype_string(const char* typestring, uint32_t* subtype, uint32_t* subsize);


#define CD_FLAG_GDROM 0x00000001 /* disc is a GD-ROM, all tracks should be stored with GD-ROM metadata */
Expand Down Expand Up @@ -117,4 +118,5 @@ static inline uint32_t lba_to_msf_alt(int lba)

#ifdef __cplusplus
} // extern "C"
#endif
#endif
#endif /* __CDROM_H__ */
207 changes: 106 additions & 101 deletions dep/libchdr/include/libchdr/chd.h

Large diffs are not rendered by default.

31 changes: 9 additions & 22 deletions dep/libchdr/include/libchdr/coretypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,13 @@
#include <streams/file_stream_transforms.h>
#endif

#ifndef ARRAY_LENGTH
#define ARRAY_LENGTH(x) (sizeof(x)/sizeof(x[0]))

#if defined(__PS3__) || defined(__PSL1GHT__)
#undef UINT32
#undef UINT16
#undef UINT8
#undef INT32
#undef INT16
#undef INT8
#endif

typedef uint64_t UINT64;
typedef uint32_t UINT32;
typedef uint16_t UINT16;
typedef uint8_t UINT8;

typedef int64_t INT64;
typedef int32_t INT32;
typedef int16_t INT16;
typedef int8_t INT8;
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
#endif

typedef struct chd_core_file {
/*
Expand All @@ -41,9 +28,9 @@ typedef struct chd_core_file {
* undefined because many implementations will seek to the end of the
* file and call ftell.
*
* on error, (UINT64)-1 is returned.
* on error, (uint64_t)-1 is returned.
*/
UINT64(*fsize)(struct chd_core_file*);
uint64_t(*fsize)(struct chd_core_file*);

/*
* should match the behavior of fread, except the FILE* argument at the end
Expand All @@ -55,7 +42,7 @@ typedef struct chd_core_file {
int (*fclose)(struct chd_core_file*);

// fseek clone
int (*fseek)(struct chd_core_file*, INT64, int);
int (*fseek)(struct chd_core_file*, int64_t, int);
} core_file;

static inline int core_fclose(core_file *fp) {
Expand All @@ -66,11 +53,11 @@ static inline size_t core_fread(core_file *fp, void *ptr, size_t len) {
return fp->fread(ptr, 1, len, fp);
}

static inline int core_fseek(core_file* fp, INT64 offset, int whence) {
static inline int core_fseek(core_file* fp, int64_t offset, int whence) {
return fp->fseek(fp, offset, whence);
}

static inline UINT64 core_fsize(core_file *fp)
static inline uint64_t core_fsize(core_file *fp)
{
return fp->fsize(fp);
}
Expand Down
2 changes: 1 addition & 1 deletion dep/libchdr/include/libchdr/huffman.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,6 @@ int huffman_build_tree(struct huffman_decoder* decoder, uint32_t totaldata, uint
enum huffman_error huffman_assign_canonical_codes(struct huffman_decoder* decoder);
enum huffman_error huffman_compute_tree_from_histo(struct huffman_decoder* decoder);

void huffman_build_lookup_table(struct huffman_decoder* decoder);
enum huffman_error huffman_build_lookup_table(struct huffman_decoder* decoder);

#endif
42 changes: 21 additions & 21 deletions dep/libchdr/src/libchdr_cdrom.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,23 @@ const char* cdrom_get_subtype_string(uint32_t subtype)
}
}

bool cdrom_parse_subtype_string(const char* typestring, uint32_t* subtype, uint32_t* subsize)
int cdrom_parse_subtype_string(const char* typestring, uint32_t* subtype, uint32_t* subsize)
{
// https://github.com/mamedev/mame/blob/d2d54fb8ed53a2e86d308067da8414f85b5929b0/src/lib/util/cdrom.cpp#L767
if (!strcmp(typestring, "RW"))
{
*subtype = CD_SUB_RAW;
*subsize = 96;
return true;
}
else if (!strcmp(typestring, "RW_RAW"))
{
*subtype = CD_SUB_RAW_INTERLEAVED;
*subsize = 96;
return true;
}

return false;
if (!strcmp(typestring, "RW"))
{
*subtype = CD_SUB_RAW;
*subsize = 96;
return 1;
}
else if (!strcmp(typestring, "RW_RAW"))
{
*subtype = CD_SUB_RAW_INTERLEAVED;
*subsize = 96;
return 1;
}

return 0;
}

#ifdef WANT_RAW_DATA_SECTOR
Expand Down Expand Up @@ -475,16 +475,16 @@ static const uint32_t edc_table[256] = {

uint32_t edc_compute(const uint8_t* data, uint32_t length)
{
uint32_t edc = 0;
for (uint32_t i = 0; i < length; i++)
edc = (edc >> 8) ^ edc_table[(edc ^ (*data++)) & 0xFF];
return edc;
uint32_t edc = 0;
for (uint32_t i = 0; i < length; i++)
edc = (edc >> 8) ^ edc_table[(edc ^ (*data++)) & 0xFF];
return edc;
}

void edc_set(uint8_t* dst, uint32_t edc)
{
// store in little-endian byte order
memcpy(dst, &edc, sizeof(edc));
// store in little-endian byte order
memcpy(dst, &edc, sizeof(edc));
}

#endif /* WANT_RAW_DATA_SECTOR */
Loading

0 comments on commit 9e5deb8

Please sign in to comment.