@@ -468,4 +468,50 @@ describe("MCPB Signing E2E Tests", () => {
468468 it ( "should remove signatures" , async ( ) => {
469469 await testSignatureRemoval ( ) ;
470470 } ) ;
471+
472+ it ( "should update EOCD comment_length after signing" , async ( ) => {
473+ const testFile = path . join ( TEST_DIR , "test-eocd.mcpb" ) ;
474+ fs . copyFileSync ( TEST_MCPB , testFile ) ;
475+
476+ // Read original EOCD comment_length
477+ const originalContent = fs . readFileSync ( testFile ) ;
478+ let eocdOffset = - 1 ;
479+ for ( let i = originalContent . length - 22 ; i >= 0 ; i -- ) {
480+ if ( originalContent . readUInt32LE ( i ) === 0x06054b50 ) {
481+ eocdOffset = i ;
482+ break ;
483+ }
484+ }
485+ expect ( eocdOffset ) . toBeGreaterThanOrEqual ( 0 ) ;
486+ const originalCommentLength = originalContent . readUInt16LE ( eocdOffset + 20 ) ;
487+ expect ( originalCommentLength ) . toBe ( 0 ) ; // Fresh ZIP has no comment
488+
489+ // Sign the file
490+ signMcpbFile ( testFile , SELF_SIGNED_CERT , SELF_SIGNED_KEY ) ;
491+
492+ // Read signed file and verify EOCD comment_length was updated
493+ const signedContent = fs . readFileSync ( testFile ) ;
494+ let signedEocdOffset = - 1 ;
495+ for ( let i = signedContent . length - 22 ; i >= 0 ; i -- ) {
496+ if ( signedContent . readUInt32LE ( i ) === 0x06054b50 ) {
497+ signedEocdOffset = i ;
498+ break ;
499+ }
500+ }
501+ expect ( signedEocdOffset ) . toBeGreaterThanOrEqual ( 0 ) ;
502+ const signedCommentLength = signedContent . readUInt16LE (
503+ signedEocdOffset + 20 ,
504+ ) ;
505+
506+ // Comment length should equal everything after the EOCD record's original end
507+ const eocdMinSize = 22 ; // minimum EOCD size (no comment)
508+ const dataAfterEocd =
509+ signedContent . length -
510+ ( signedEocdOffset + eocdMinSize + originalCommentLength ) ;
511+ expect ( signedCommentLength ) . toBe ( dataAfterEocd ) ;
512+ expect ( signedCommentLength ) . toBeGreaterThan ( 0 ) ;
513+
514+ // Clean up
515+ fs . unlinkSync ( testFile ) ;
516+ } ) ;
471517} ) ;
0 commit comments