Beuc
Joined: 26 Mar 2009 Posts: 33 Location: holland
|
Posted: Thu Apr 09, 2009 5:54 am Post subject: [psp][zziplib] fix crash (misaligned pointer access) |
|
|
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: |
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 .................... */
|
|
|