FILE_METADATA_WIRE_SIZE is not portable between 32-bit and 64-bit systems #51

Closed
opened 2026-07-20 17:14:07 +02:00 by TapTap · 0 comments
Owner

Description

In src/shared/metadata.h line 8-9, FILE_METADATA_WIRE_SIZE is computed based on compile-time type sizes:

#define FILE_METADATA_WIRE_SIZE  (sizeof(mode_t) + sizeof(uid_t) + sizeof(gid_t) + sizeof(time_t) + sizeof(long))

Type sizes differ between architectures:

  • 64-bit Linux: mode_t=4, uid_t=4, gid_t=4, time_t=8, long=8 → 28 bytes
  • 32-bit Linux: mode_t=4, uid_t=4, gid_t=4, time_t=4, long=4 → 20 bytes

The metadata wire format uses metadata_to_buf/metadata_from_buf which serializes/deserializes these types directly with memcpy. If a 32-bit client communicates with a 64-bit server, the metadata wire format will be interpreted differently, causing data corruption or crashes.

Location

src/shared/metadata.h:8-9, src/shared/metadata.c:11-47

Suggested Fix

Use fixed-width integer types for the wire format instead of relying on sizeof() for native types. Define explicit wire-format fields:

#define METADATA_WIRE_MODE_SIZE  4    // always uint32_t
#define METADATA_WIRE_UID_SIZE   4    // always uint32_t
#define METADATA_WIRE_GID_SIZE   4    // always uint32_t
#define METADATA_WIRE_MTIME_SEC_SIZE  8  // always int64_t
#define METADATA_WIRE_MTIME_NSEC_SIZE 8  // always int64_t

Then explicitly cast or convert each field when serializing and deserializing.

Severity

High

Category

Bug

## Description In `src/shared/metadata.h` line 8-9, `FILE_METADATA_WIRE_SIZE` is computed based on compile-time type sizes: ```c #define FILE_METADATA_WIRE_SIZE (sizeof(mode_t) + sizeof(uid_t) + sizeof(gid_t) + sizeof(time_t) + sizeof(long)) ``` Type sizes differ between architectures: - **64-bit Linux**: mode_t=4, uid_t=4, gid_t=4, time_t=8, long=8 → 28 bytes - **32-bit Linux**: mode_t=4, uid_t=4, gid_t=4, time_t=4, long=4 → 20 bytes The metadata wire format uses `metadata_to_buf`/`metadata_from_buf` which serializes/deserializes these types directly with `memcpy`. If a 32-bit client communicates with a 64-bit server, the metadata wire format will be interpreted differently, causing data corruption or crashes. ## Location `src/shared/metadata.h:8-9`, `src/shared/metadata.c:11-47` ## Suggested Fix Use fixed-width integer types for the wire format instead of relying on `sizeof()` for native types. Define explicit wire-format fields: ```c #define METADATA_WIRE_MODE_SIZE 4 // always uint32_t #define METADATA_WIRE_UID_SIZE 4 // always uint32_t #define METADATA_WIRE_GID_SIZE 4 // always uint32_t #define METADATA_WIRE_MTIME_SEC_SIZE 8 // always int64_t #define METADATA_WIRE_MTIME_NSEC_SIZE 8 // always int64_t ``` Then explicitly cast or convert each field when serializing and deserializing. ## Severity High ## Category Bug
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: TapTap/FastSync#51