Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix compression on big-endian architecture #120

Merged
merged 1 commit into from

2 participants

Vincent Bernat Mikko Koppanen
Vincent Bernat

On big-endian architecture where size_t is a 64-bit long,
copying the 4 first bytes as the size is incorrect. We cast it to an
unsigned 32-bit integer before copying it at the beginning of the
provided buffer.

Vincent Bernat vincentbernat Fix compression on big-endian architecture
On big-endian architecture where size_t is a 64-bit long,
copying the 4 first bytes as the size is incorrect. We cast it to an
unsigned 32-bit integer before copying it at the beginning of the
provided buffer.
98e7e6b
Mikko Koppanen mkoppanen merged commit 304806f into from
Mikko Koppanen
Owner

Looking at this I guess ideally storing network ordered and converting to host byte order on receive would make most change (but also break backwards compatibility).

Vincent Bernat

I don't think it is worth it.

Mikko Koppanen
Owner

I opened a pull, which fixes the issue in a backwards compatible manner. Haven't merged yet because not sure if it's worth it (in practice x86/x86-64 will be used by the majority).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 8, 2014
  1. Vincent Bernat

    Fix compression on big-endian architecture

    vincentbernat authored
    On big-endian architecture where size_t is a 64-bit long,
    copying the 4 first bytes as the size is incorrect. We cast it to an
    unsigned 32-bit integer before copying it at the beginning of the
    provided buffer.
This page is out of date. Refresh to see the latest.
Showing with 2 additions and 1 deletion.
  1. +2 −1  php_memcached.c
3  php_memcached.c
View
@@ -3084,9 +3084,10 @@ char *s_compress_value (enum memcached_compression_type compression_type, const
/* Store compressed size here */
size_t compressed_size = 0;
+ uint32_t plen = *payload_len;
/* Copy the uin32_t at the beginning */
- memcpy(buffer, payload_len, sizeof(uint32_t));
+ memcpy(buffer, &plen, sizeof(uint32_t));
buffer += sizeof(uint32_t);
switch (compression_type) {
Something went wrong with that request. Please try again.