@@ -137,6 +137,13 @@ export const parseCArchiveToc = (
137137) : Result < readonly CArchiveEntry [ ] , PyInstallerFailure > => {
138138 const entries : CArchiveEntry [ ] = [ ] ;
139139 let offset = 0 ;
140+ const malformedEntry = ( message : string ) : Result < never , PyInstallerFailure > =>
141+ err (
142+ pyInstallerFailure (
143+ "format" ,
144+ `CArchive table index ${ String ( entries . length ) } at TOC offset ${ String ( offset ) } : ${ message } ` ,
145+ ) ,
146+ ) ;
140147 while ( offset < bytes . length ) {
141148 if ( entries . length >= MAX_TOC_ENTRIES )
142149 return err (
@@ -146,42 +153,26 @@ export const parseCArchiveToc = (
146153 ) ,
147154 ) ;
148155 if ( offset + TOC_HEADER_BYTES > bytes . length )
149- return err (
150- pyInstallerFailure (
151- "format" ,
152- "CArchive table of contents entry is truncated" ,
153- ) ,
154- ) ;
156+ return malformedEntry ( "CArchive table of contents entry is truncated" ) ;
155157 const entryLength = bytes . readUInt32BE ( offset ) ;
156158 if ( entryLength < TOC_HEADER_BYTES || offset + entryLength > bytes . length )
157- return err (
158- pyInstallerFailure (
159- "format" ,
160- "CArchive table of contents entry extends outside the table" ,
161- ) ,
159+ return malformedEntry (
160+ "CArchive table of contents entry extends outside the table" ,
162161 ) ;
163162 const nameBytes = bytes . subarray (
164163 offset + TOC_HEADER_BYTES ,
165164 offset + entryLength ,
166165 ) ;
167166 const name = tocName ( nameBytes ) ;
168- if ( ! name . ok ) return name ;
167+ if ( ! name . ok ) return malformedEntry ( name . error . message ) ;
169168 const compressionFlag = bytes [ offset + 16 ] ?? 0 ;
170169 if ( compressionFlag !== 0 && compressionFlag !== 1 )
171- return err (
172- pyInstallerFailure (
173- "format" ,
174- `CArchive compression flag ${ String ( compressionFlag ) } is not stored or zlib` ,
175- ) ,
170+ return malformedEntry (
171+ `CArchive compression flag ${ String ( compressionFlag ) } is not stored or zlib` ,
176172 ) ;
177173 const typeCode = bytes [ offset + 17 ] ?? 0 ;
178174 if ( typeCode < 0x20 || typeCode > 0x7e )
179- return err (
180- pyInstallerFailure (
181- "format" ,
182- "CArchive type code is not a printable character" ,
183- ) ,
184- ) ;
175+ return malformedEntry ( "CArchive type code is not a printable character" ) ;
185176 entries . push ( {
186177 index : entries . length ,
187178 tocRecordOffset : offset ,
0 commit comments