File tree Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,8 @@ const CD_SIGNATURE = 0x02014b50;
8
8
const CENTRAL_DIRECTORY_RECORD_FIXED_SIZE = 46 ;
9
9
const LOCAL_FILE_HEADER_FIXED_SIZE = 30 ;
10
10
const VERSION_NEEDED_TO_EXTRACT_ZIP64 = 45 ;
11
+ const manifestMaxSize = 1024 * 1024 * 10 ; // 10 MB
12
+
11
13
const cp437 =
12
14
'\u0000☺☻♥♦♣♠•◘○◙♂♀♪♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼ !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~⌂ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■ ' ;
13
15
@@ -92,6 +94,11 @@ export class ZipReader {
92
94
throw new Error ( 'Unable to retrieve CD manifest' ) ;
93
95
}
94
96
const byteStart = cdObj . relativeOffsetOfLocalHeader + cdObj . headerLength ;
97
+ if ( cdObj . uncompressedSize > manifestMaxSize ) {
98
+ throw new Error (
99
+ `manifest file too large: ${ ( cdObj . uncompressedSize >> 10 ) . toLocaleString ( ) } KiB`
100
+ ) ;
101
+ }
95
102
const byteEnd = byteStart + cdObj . uncompressedSize ;
96
103
const manifest = await this . getChunk ( byteStart , byteEnd ) ;
97
104
Original file line number Diff line number Diff line change 1
1
import { expect } from 'chai' ;
2
2
3
3
import { encodeArrayBuffer } from '../../../src/encodings/base64.js' ;
4
- import { parseCDBuffer , readUInt64LE } from '../../../tdf3/src/utils/zip-reader.js' ;
4
+ import {
5
+ CentralDirectory ,
6
+ parseCDBuffer ,
7
+ readUInt64LE ,
8
+ ZipReader ,
9
+ } from '../../../tdf3/src/utils/zip-reader.js' ;
5
10
import { ZipWriter , dateToDosDateTime , writeUInt64LE } from '../../../tdf3/src/utils/zip-writer.js' ;
6
11
7
12
describe ( 'zip utilities' , ( ) => {
@@ -170,3 +175,27 @@ describe('zip utilities', () => {
170
175
} ) ;
171
176
} ) ;
172
177
} ) ;
178
+
179
+ describe ( 'reader' , ( ) => {
180
+ it ( 'fails on bad manifest size' , async ( ) => {
181
+ const reader = new ZipReader ( async ( ) => new Uint8Array ( [ ] ) ) ;
182
+ const fileName = '0.manifest.json' ;
183
+ try {
184
+ expect (
185
+ await reader . getManifest (
186
+ [
187
+ {
188
+ fileName,
189
+ relativeOffsetOfLocalHeader : 0 ,
190
+ headerLength : 1024 ,
191
+ uncompressedSize : 1024 * 1024 * 128 ,
192
+ } as CentralDirectory ,
193
+ ] ,
194
+ fileName
195
+ )
196
+ ) . to . be . undefined ;
197
+ } catch ( e ) {
198
+ expect ( e . message ) . to . contain ( 'too large' ) ;
199
+ }
200
+ } ) ;
201
+ } ) ;
You can’t perform that action at this time.
0 commit comments