Skip to content

Commit

Permalink
CDImageCHD: Show precaching in MB
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Nov 4, 2024
1 parent be271e3 commit bb74049
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
13 changes: 7 additions & 6 deletions dep/libchdr/src/libchdr_chd.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@

#define CHD_V1_SECTOR_SIZE 512 /* size of a "sector" in the V1 header */

#define CHD_MAX_HUNK_SIZE (128 * 1024 * 1024) /* hunk size probably shouldn't be more than 128MB */

/* we're currently only using this for CD/DVDs, if we end up with more than 10GB data, it's probably invalid */
#define CHD_MAX_FILE_SIZE (10ULL * 1024 * 1024 * 1024)

#define COOKIE_VALUE 0xbaadf00d
#define MAX_ZLIB_ALLOCS 64

Expand Down Expand Up @@ -2587,12 +2592,8 @@ static chd_error header_validate(const chd_header *header)
return CHDERR_INVALID_PARAMETER;
}

/* some basic size checks to prevent huge mallocs: hunk size probably shouldn't be more than 128MB */
if (header->hunkbytes >= (128 * 1024 * 1024))
return CHDERR_INVALID_PARAMETER;

/* - we're currently only using this for CD/DVDs, if we end up with more than 10GB data, it's probably invalid */
if (((uint64_t)header->hunkbytes * (uint64_t)header->totalhunks) >= (10ULL * 1024 * 1024 * 1024))
/* some basic size checks to prevent huge mallocs */
if (header->hunkbytes >= CHD_MAX_HUNK_SIZE || ((uint64_t)header->hunkbytes * (uint64_t)header->totalhunks) >= CHD_MAX_FILE_SIZE)
return CHDERR_INVALID_PARAMETER;

return CHDERR_NONE;
Expand Down
5 changes: 3 additions & 2 deletions src/util/cd_image_chd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,9 @@ CDImage::PrecacheResult CDImageCHD::Precache(ProgressCallback* progress)
progress->SetProgressRange(100);

auto callback = [](size_t pos, size_t total, void* param) {
const u32 percent = static_cast<u32>((pos * 100) / total);
static_cast<ProgressCallback*>(param)->SetProgressValue(std::min<u32>(percent, 100));
constexpr size_t one_mb = 1048576;
static_cast<ProgressCallback*>(param)->SetProgressRange(static_cast<u32>((total + (one_mb - 1)) / one_mb));
static_cast<ProgressCallback*>(param)->SetProgressValue(static_cast<u32>((pos + (one_mb - 1)) / one_mb));
};

if (chd_precache_progress(m_chd, callback, progress) != CHDERR_NONE)
Expand Down

0 comments on commit bb74049

Please sign in to comment.