When trying to transmux or inspect the attached ts segment, mux.js crashes because the pmt parsing returns an undefined value that the caller tries to use as a non empty object. This PR adds fallbacks to use empty objects when that happens.
Here is a typescript file that reproduces the problem:
import { mp2t } from 'mux.js';
import fs from 'fs';
main(process.argv.slice(2)).catch(err => console.error(err));
async function main(args: string[]) {
for (const file of args) {
const buffer = fs.readFileSync(file);
const tsInfo = mp2t.tools.inspect(buffer);
console.log(`File ${file}: ${JSON.stringify(tsInfo, null, 2)}`);
}
}
Without the fix, the output is as follows:
$ muxProbe ~/Desktop/pmt.ts
TypeError: Cannot convert undefined or null to object
at Function.keys (<anonymous>)
at parsePsi_2 (..../muxProbe.js:7423:20)
at inspectTs_2 (..../muxProbe.js:7705:5)
at Object.inspect2 [as inspect] (..../muxProbe.js:7737:16)
at main (..../muxProbe.js:7774:42)
at Object.<anonymous> (..../muxProbe.js:7770:1)
at Module._compile (node:internal/modules/cjs/loader:1254:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
at Module.load (node:internal/modules/cjs/loader:1117:32)
at Module._load (node:internal/modules/cjs/loader:958:12)
When trying to transmux or inspect the attached ts segment, mux.js crashes because the pmt parsing returns an undefined value that the caller tries to use as a non empty object. This PR adds fallbacks to use empty objects when that happens.
Here is a typescript file that reproduces the problem:
Without the fix, the output is as follows:
With the fix, it works as expected:
pmt.ts.zip