Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/compiler/sys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ namespace ts {
const Buffer: {
new (input: string, encoding?: string): any;
from?(input: string, encoding?: string): any;
alloc(length: number): any;
} = require("buffer").Buffer;

const nodeVersion = getNodeMajorVersion();
Expand Down Expand Up @@ -984,6 +985,30 @@ namespace ts {
if (!fileExists(fileName)) {
return undefined;
}

{
// GH#21136: check if this is an MPEG-TS file
const buffer = Buffer.alloc(50 * 188);
const fd = _fs.openSync(fileName, "r");
try {
const bytesRead = _fs.readSync(fd, buffer, 0, 50 * 188);
// check if we have a multiple of 188 bytes (frames)
if (bytesRead > 0 && bytesRead % 188 === 0) {
let allHex47 = true;
for (let i = 0, n = 50 * 188; i < n; i = i + 188) {
if (i < bytesRead && buffer[i] !== 0x47) {
allHex47 = false;
}
}
if (allHex47) {
return undefined;
}
}
} finally {
_fs.closeSync(fd);
}
}

const buffer = _fs.readFileSync(fileName);
let len = buffer.length;
if (len >= 2 && buffer[0] === 0xFE && buffer[1] === 0xFF) {
Expand Down