@@ -714,6 +714,7 @@ read_directory(PyObject *archive_obj)
714714 /* FIXME: work on Py_UNICODE* instead of char* */
715715 PyObject * files = NULL ;
716716 FILE * fp ;
717+ unsigned short flags ;
717718 long compress , crc , data_size , file_size , file_offset , date , time ;
718719 long header_offset , name_size , header_size , header_position ;
719720 long i , l , count ;
@@ -724,6 +725,7 @@ read_directory(PyObject *archive_obj)
724725 char * p , endof_central_dir [22 ];
725726 long arc_offset ; /* offset from beginning of file to start of zip-archive */
726727 PyObject * pathobj ;
728+ const char * charset ;
727729
728730 if (PyUnicode_GET_SIZE (archive_obj ) > MAXPATHLEN ) {
729731 PyErr_SetString (PyExc_OverflowError ,
@@ -776,7 +778,8 @@ read_directory(PyObject *archive_obj)
776778 l = PyMarshal_ReadLongFromFile (fp );
777779 if (l != 0x02014B50 )
778780 break ; /* Bad: Central Dir File Header */
779- fseek (fp , header_offset + 10 , 0 );
781+ fseek (fp , header_offset + 8 , 0 );
782+ flags = (unsigned short )PyMarshal_ReadShortFromFile (fp );
780783 compress = PyMarshal_ReadShortFromFile (fp );
781784 time = PyMarshal_ReadShortFromFile (fp );
782785 date = PyMarshal_ReadShortFromFile (fp );
@@ -802,7 +805,11 @@ read_directory(PyObject *archive_obj)
802805 * p = 0 ; /* Add terminating null byte */
803806 header_offset += header_size ;
804807
805- nameobj = PyUnicode_DecodeFSDefaultAndSize (name , name_size );
808+ if (flags & 0x0800 )
809+ charset = "utf-8" ;
810+ else
811+ charset = "cp437" ;
812+ nameobj = PyUnicode_Decode (name , name_size , charset , NULL );
806813 if (nameobj == NULL )
807814 goto error ;
808815 Py_UNICODE_strncpy (path + length + 1 , PyUnicode_AS_UNICODE (nameobj ), MAXPATHLEN - length - 1 );
0 commit comments