Skip to content

Commit

Permalink
src: use goffset for checksum 'size' struct member
Browse files Browse the repository at this point in the history
Using gsize is inappropriate for describing file sizes as gsize refers
to the pointer size and thus is normally 32bit on 32bit systems which
limits the possible artifact size to 2GB.

We change this to goffset which is typedefed as gint64 and thus always
64bit large. goffset is the default type for size and offset information
in glib anyway and the pendant to the POSIX off_t type.

Signed-off-by: Enrico Joerns <[email protected]>
  • Loading branch information
ejoerns committed Jan 9, 2020
1 parent 326b580 commit d6161a5
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion include/checksum.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ GQuark r_checksum_error_quark(void);
typedef struct {
GChecksumType type;
gchar *digest;
gsize size;
goffset size;
} RaucChecksum;

/**
Expand Down
6 changes: 3 additions & 3 deletions src/checksum.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ G_STATIC_ASSERT(RAUC_DEFAULT_CHECKSUM != 0);
G_DEFINE_QUARK(r-checksum-error-quark, r_checksum_error)

static gboolean
update_from_file(GChecksum *ctx, const gchar *filename, gsize *total, GError **error)
update_from_file(GChecksum *ctx, const gchar *filename, goffset *total, GError **error)
{
g_auto(filedesc) fd = -1;
gsize size = 0;
goffset size = 0;
gssize r;
guchar buf[4096];

Expand Down Expand Up @@ -51,7 +51,7 @@ gboolean compute_checksum(RaucChecksum *checksum, const gchar *filename, GError
{
g_autoptr(GChecksum) ctx = NULL;
GChecksumType type = checksum->type;
gsize total = 0;
goffset total = 0;

g_return_val_if_fail(error == NULL || *error == NULL, FALSE);

Expand Down
12 changes: 6 additions & 6 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ static gchar *info_formatter_shell(RaucManifest *manifest)
formatter_shell_append_n(text, "RAUC_IMAGE_CLASS", cnt, img->slotclass);
formatter_shell_append_n(text, "RAUC_IMAGE_VARIANT", cnt, img->variant);
formatter_shell_append_n(text, "RAUC_IMAGE_DIGEST", cnt, img->checksum.digest);
g_string_append_printf(text, "RAUC_IMAGE_SIZE_%d=%"G_GSIZE_FORMAT "\n", cnt, img->checksum.size);
g_string_append_printf(text, "RAUC_IMAGE_SIZE_%d=%"G_GOFFSET_FORMAT "\n", cnt, img->checksum.size);

hooks = g_ptr_array_new();
if (img->hooks.pre_install == TRUE) {
Expand Down Expand Up @@ -712,7 +712,7 @@ static gchar *info_formatter_shell(RaucManifest *manifest)
g_string_append_printf(text, "RAUC_FILE_CLASS_%d=%s\n", cnt, file->slotclass);
g_string_append_printf(text, "RAUC_FILE_DEST_%d=%s\n", cnt, file->destname);
g_string_append_printf(text, "RAUC_FILE_DIGEST_%d=%s\n", cnt, file->checksum.digest);
g_string_append_printf(text, "RAUC_FILE_SIZE_%d=%"G_GSIZE_FORMAT "\n", cnt, file->checksum.size);
g_string_append_printf(text, "RAUC_FILE_SIZE_%d=%"G_GOFFSET_FORMAT "\n", cnt, file->checksum.size);
cnt++;
}

Expand Down Expand Up @@ -753,7 +753,7 @@ static gchar *info_formatter_readable(RaucManifest *manifest)
if (img->variant)
g_string_append_printf(text, "\tVariant: %s\n", img->variant);
g_string_append_printf(text, "\tChecksum: %s\n", img->checksum.digest);
g_string_append_printf(text, "\tSize: %"G_GSIZE_FORMAT "\n", img->checksum.size);
g_string_append_printf(text, "\tSize: %"G_GOFFSET_FORMAT "\n", img->checksum.size);

hooks = g_ptr_array_new();
if (img->hooks.pre_install == TRUE) {
Expand Down Expand Up @@ -785,7 +785,7 @@ static gchar *info_formatter_readable(RaucManifest *manifest)
g_string_append_printf(text, "\tSlotclass: %s\n", file->slotclass);
g_string_append_printf(text, "\tDest: %s\n", file->destname);
g_string_append_printf(text, "\tChecksum: %s\n", file->checksum.digest);
g_string_append_printf(text, "\tSize: %"G_GSIZE_FORMAT "\n", file->checksum.size);
g_string_append_printf(text, "\tSize: %"G_GOFFSET_FORMAT "\n", file->checksum.size);
cnt++;
}

Expand Down Expand Up @@ -1038,7 +1038,7 @@ static void r_string_append_slot(GString *text, RaucSlot *slot, RaucStatusPrint
if (slot_state->checksum.digest && slot_state->checksum.type == G_CHECKSUM_SHA256) {
g_string_append_printf(text, "\n checksum:");
g_string_append_printf(text, "\n sha256=%s", slot_state->checksum.digest);
g_string_append_printf(text, "\n size=%"G_GSIZE_FORMAT, slot_state->checksum.size);
g_string_append_printf(text, "\n size=%"G_GOFFSET_FORMAT, slot_state->checksum.size);
}
if (slot_state->installed_timestamp) {
g_string_append_printf(text, "\n installed:");
Expand Down Expand Up @@ -1166,7 +1166,7 @@ static gchar* r_status_formatter_shell(RaucStatusPrint *status)
formatter_shell_append_n(text, "RAUC_SLOT_STATUS_BUNDLE_DESCRIPTION", slotcnt, slot_state->bundle_description);
formatter_shell_append_n(text, "RAUC_SLOT_STATUS_BUNDLE_BUILD", slotcnt, slot_state->bundle_build);
formatter_shell_append_n(text, "RAUC_SLOT_STATUS_CHECKSUM_SHA256", slotcnt, slot_state->checksum.digest);
str = g_strdup_printf("%"G_GSIZE_FORMAT, slot_state->checksum.size);
str = g_strdup_printf("%"G_GOFFSET_FORMAT, slot_state->checksum.size);
formatter_shell_append_n(text, "RAUC_SLOT_STATUS_CHECKSUM_SIZE", slotcnt, str);
g_free(str);
formatter_shell_append_n(text, "RAUC_SLOT_STATUS_INSTALLED_TIMESTAMP", slotcnt, slot_state->installed_timestamp);
Expand Down
2 changes: 1 addition & 1 deletion src/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ gboolean download_file_checksum(const gchar *target, const gchar *url,
g_autofree gchar *tmppath = NULL;
gboolean res = FALSE;

tmpname = g_strdup_printf(".rauc_%s_%"G_GSIZE_FORMAT, checksum->digest,
tmpname = g_strdup_printf(".rauc_%s_%"G_GOFFSET_FORMAT, checksum->digest,
checksum->size);
dir = g_path_get_dirname(target);
tmppath = g_build_filename(dir, tmpname, NULL);
Expand Down
6 changes: 3 additions & 3 deletions src/update_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ static gboolean copy_raw_image(RaucImage *image, GUnixOutputStream *outstream, G
return FALSE;
} else if (size != (gssize)image->checksum.size) {
g_set_error(error, R_UPDATE_ERROR, R_UPDATE_ERROR_FAILED,
"Written size (%"G_GSIZE_FORMAT ") != image size (%"G_GSIZE_FORMAT ")", size, (gssize)image->checksum.size);
"Written size (%"G_GSIZE_FORMAT ") != image size (%"G_GOFFSET_FORMAT ")", size, image->checksum.size);
return FALSE;
}

Expand Down Expand Up @@ -1166,9 +1166,9 @@ static gboolean img_to_boot_mbr_switch_handler(RaucImage *image, RaucSlot *dest_
g_message("Found inactive boot partition %d (pos. %"G_GUINT64_FORMAT "B, size %"G_GUINT64_FORMAT "B)",
inactive_part, dest_partition.start, dest_partition.size);

if (dest_partition.size < image->checksum.size) {
if (dest_partition.size < (guint64)image->checksum.size) {
g_set_error(error, R_UPDATE_ERROR, R_UPDATE_ERROR_FAILED,
"Size of image (%"G_GSIZE_FORMAT ") does not fit to slot size %"G_GUINT64_FORMAT,
"Size of image (%"G_GOFFSET_FORMAT ") does not fit to slot size %"G_GUINT64_FORMAT,
image->checksum.size, dest_partition.size);
res = FALSE;
goto out;
Expand Down

0 comments on commit d6161a5

Please sign in to comment.