W
File size: 778 Bytes
2b64d42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import { describe, it } from 'node:test';
import assert from 'node:assert/strict';
import { deflateSync } from 'node:zlib';
import { tryExtractPdf } from '../src/pdf.js';

describe('PDF extraction safety limits', () => {
  it('falls back when a compressed stream expands beyond the per-stream limit', () => {
    const inflated = Buffer.alloc(6 * 1024 * 1024, 0x20);
    const compressed = deflateSync(inflated);
    const pdf = Buffer.concat([
      Buffer.from('%PDF-1.4\n1 0 obj\n<< /Length ' + compressed.length + ' /Filter /FlateDecode >>\nstream\n', 'latin1'),
      compressed,
      Buffer.from('\nendstream\nendobj\n%%EOF', 'latin1'),
    ]);
    const result = tryExtractPdf(pdf.toString('base64'));
    assert.equal(result.text, 'PDF 内容无法提取');
  });
});