@@ -266,26 +266,32 @@ impl<'a> Section<'a> {
266266 SectionContent :: DataCount ( self . get_data_count_section_content ( ) ?)
267267 }
268268 SectionCode :: Custom { kind, name } => {
269+ // The invalid custom section may cause trouble during
270+ // content() call. The spec recommends to ignore erroneous
271+ // content in custom section.
272+ // Return None in the content field if invalid.
269273 let binary = self . get_binary_reader ( ) ;
270274 let content = match kind {
271- CustomSectionKind :: Name => {
272- Some ( CustomSectionContent :: Name ( self . get_name_section_reader ( ) ?) )
273- }
274- CustomSectionKind :: Producers => Some ( CustomSectionContent :: Producers (
275- self . get_producers_section_reader ( ) ?,
276- ) ) ,
277- CustomSectionKind :: Linking => Some ( CustomSectionContent :: Linking (
278- self . get_linking_section_reader ( ) ?,
279- ) ) ,
280- CustomSectionKind :: Reloc => Some ( CustomSectionContent :: Reloc (
281- self . get_reloc_section_reader ( ) ?,
282- ) ) ,
283- CustomSectionKind :: SourceMappingURL => {
284- Some ( CustomSectionContent :: SourceMappingURL (
285- self . get_sourcemappingurl_section_content ( ) ?,
286- ) )
287- }
288-
275+ CustomSectionKind :: Name => self
276+ . get_name_section_reader ( )
277+ . ok ( )
278+ . map ( CustomSectionContent :: Name ) ,
279+ CustomSectionKind :: Producers => self
280+ . get_producers_section_reader ( )
281+ . ok ( )
282+ . map ( CustomSectionContent :: Producers ) ,
283+ CustomSectionKind :: Linking => self
284+ . get_linking_section_reader ( )
285+ . ok ( )
286+ . map ( CustomSectionContent :: Linking ) ,
287+ CustomSectionKind :: Reloc => self
288+ . get_reloc_section_reader ( )
289+ . ok ( )
290+ . map ( CustomSectionContent :: Reloc ) ,
291+ CustomSectionKind :: SourceMappingURL => self
292+ . get_sourcemappingurl_section_content ( )
293+ . ok ( )
294+ . map ( CustomSectionContent :: SourceMappingURL ) ,
289295 _ => None ,
290296 } ;
291297 SectionContent :: Custom {
0 commit comments