forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

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

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> Patch Submissions
View previous topic :: View next topic  
Author Message
Beuc



Joined: 26 Mar 2009
Posts: 33
Location: holland

PostPosted: Thu Apr 09, 2009 5:54 am    Post subject: [psp][zziplib] fix crash (misaligned pointer access) Reply with quote

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 .................... */
Back to top
View user's profile Send private message
jimparis



Joined: 10 Jun 2005
Posts: 1179
Location: Boston

PostPosted: Wed Apr 15, 2009 4:20 am    Post subject: Reply with quote

Added in rev 2456, thanks
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> Patch Submissions All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group