[psp][zziplib] fix crash (misaligned pointer access)

Create a single thread for each patch to be added to the repository. Please try to stay on topic.
Post Reply
Beuc
Posts: 33
Joined: Thu Mar 26, 2009 5:04 am
Location: holland

[psp][zziplib] fix crash (misaligned pointer access)

Post by Beuc »

zziplib makes a misaligned 32bit pointer dereference, which causes a crash, at least when the zip has a preamble. This was further discussed and diagnosed at http://forums.ps2dev.org/viewtopic.php?t=11864

This patch makes zziplib always rely on portable char[4]->int conversion instead of the less portable "*(int*)p" trick that only works on 32bit-aligned addresses.

Code: Select all

Index: zzip/fetch.h
===================================================================
--- zzip/fetch.h	(révision 2455)
+++ zzip/fetch.h	(copie de travail)
@@ -15,23 +15,16 @@
 extern void     __zzip_set32(unsigned char * s, uint32_t v);
 extern void     __zzip_set16(unsigned char * s, uint16_t v);
 
-#ifdef ZZIP_WORDS_BIGENDIAN
-# if defined bswap_16 && defined bswap_32 /* a.k.a. linux */
+#ifdef ZZIP_WORDS_BIGENDIAN && defined bswap_16 && defined bswap_32 /* a.k.a. linux */
 # define ZZIP_GET16(__p)                        bswap_16(*(uint16_t*)(__p))
 # define ZZIP_GET32(__p)                        bswap_32(*(uint32_t*)(__p))
 # define ZZIP_SET16(__p,__x) (*(uint16_t*)(__p) = bswap_16((uint16_t)(__x)))
 # define ZZIP_SET32(__p,__x) (*(uint32_t*)(__p) = bswap_32((uint32_t)(__x)))
-# else
+#else
 # define ZZIP_GET32(__p)     (__zzip_get32((__p)))
 # define ZZIP_GET16(__p)     (__zzip_get16((__p)))
 # define ZZIP_SET32(__p,__x) (__zzip_set32((__p),(__x)))
 # define ZZIP_SET16(__p,__x) (__zzip_set16((__p),(__x)))
-# endif
-#else /* little endian is the original zip format byteorder */
-# define ZZIP_GET16(__p)     (*(uint16_t*)(__p))
-# define ZZIP_GET32(__p)     (*(uint32_t*)(__p))
-# define ZZIP_SET16(__p,__x) (*(uint16_t*)(__p) = (uint16_t)(__x))
-# define ZZIP_SET32(__p,__x) (*(uint32_t*)(__p) = (uint32_t)(__x))
 #endif
 
 /* ..................... bitcorrect physical access .................... */
jimparis
Posts: 1145
Joined: Fri Jun 10, 2005 4:21 am
Location: Boston

Post by jimparis »

Added in rev 2456, thanks
Post Reply