swadhinbiswas chore: rename monorepo and package scopes to VidoLib (@vidolib/*) · 7/23/2026
11fee02
71 lines · 2.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { ContainerDemuxer } from '@vidolib/containers';

export interface FuzzResult {
  iterations: number;
  crashes: number;
  unboundedAllocations: number;
  errors: Array<{ iteration: number; message: string }>;
}

export class ByteMutator {
  public static mutate(input: Uint8Array, mutationRate: number = 0.05): Uint8Array {
    const mutated = new Uint8Array(input);
    const count = Math.ceil(mutated.length * mutationRate);

    for (let i = 0; i < count; i++) {
      const idx = Math.floor(Math.random() * mutated.length);
      const mode = Math.random();

      if (mode < 0.33) {
        mutated[idx] = Math.floor(Math.random() * 256);
      } else if (mode < 0.66) {
        mutated[idx] ^= 0xFF;
      } else {
        mutated[idx] = 0xFF;
      }
    }
    return mutated;
  }
}

export class FuzzTarget {
  public static run(demuxer: ContainerDemuxer, seedSample: Uint8Array, iterations: number = 1000): FuzzResult {
    let crashes = 0;
    let unboundedAllocations = 0;
    const errors: Array<{ iteration: number; message: string }> = [];

    for (let i = 0; i < iterations; i++) {
      const mutated = ByteMutator.mutate(seedSample);
      try {
        demuxer.demux(mutated);
      } catch (err: any) {
        const msg = err?.message || String(err);
        if (
          msg.includes('exceeds maximum safety limit') ||
          msg.includes('Security') ||
          msg.includes('RangeError') ||
          msg.includes('End of Stream') ||
          msg.includes('out of bounds')
        ) {
          // Expected catch
        } else {
          crashes++;
          errors.push({ iteration: i, message: msg });
        }
      }
    }

    return { iterations, crashes, unboundedAllocations, errors };
  }
}

export const CSP_RECOMMENDED_DIRECTIVES = `
# VidoLib Recommended Content Security Policy (CSP)
default-src 'self';
script-src 'self' 'wasm-unsafe-eval' blob:;
worker-src 'self' blob:;
connect-src 'self' https: wss: ipfs:;
media-src 'self' blob: data:;
img-src 'self' blob: data:;
`;