-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Code Helper attempts to index MPEG-TS files in project and eats 100% cpu #21136
Comments
From @usernamehw on January 10, 2018 23:34 I wonder if you can exclude media folder(or files) from tsconfig.json: {
// ...
"exclude": [
"media"
]
} |
There are workarounds we can tell users about on the VSCode side, but moving over to TS to see if the server should be smarter detecting if a file is binary when indexing |
not sure what we can do here.. one option is to bailout on parsing if we see too many parse errors.. |
I have a pretty novel idea: check for data[0] == 0x47 and data[188] == 0x47 // assume this is a mpeg-ts file. You could go through the whole file if you wanted to be "extra" sure. |
I'm not sure what the convention is about where to continue discussion when an issue is a duplicate, but: To explain @jon-valliere 's suggestion of reading
The @mhegazy As an alternative to bailing out on high numbers of parse errors, one could bail out if the file size of the .ts file is above a default (yet configurable) threshold, say, 1MB. Java has a similar restriction, wherein the bytecode generated for any method needs to be under 64kB, although I believe that's a hard limit. We are already doing something similar for large JS projects with |
@mjbvz Yes, I've tested just now, and that |
@mhegazy proposing that we bail on files that are > 500 kB and match the above heuristic?
|
so you think |
Probably both; just treat a file like that as having invalid encoding or something. |
@shirakaba I wouldn't imagine that a file containing a single 188 byte MPEG-TS packet would cause the TypeScript compiler to hang forever. Not like a 65MB MPEG-TS file does. |
@mhegazy I guess you could check the entire file, at 188 byte intervals for the |
A PR would be appreciated. We would follow @jon-valliere's suggestions and check on 188 intervals the input text, then raise an error for an invalid file content if true. |
MPEG-TS files can be considerably big (eg. a full Blu-Ray disc can hold 25-50 GB as BDAV MPEG-TS – so if exported to regular MPEG-TS without further compression, would give that kind of ballpark – and one hour of a recorded HD television-quality stream can come to ~1.6 GB). I would recommend not checking the entire file if it would cause a large disc read. A few packets should suffice. Hard disc drives read at ~128 MB/s, and we should aim not to hang on a file for more than a fraction of a second, so how about analysing some (very) small fraction of 128 MB (but as Ryan says, only for files above 500 KB)? Edit: Before, I accidentally mistook packets to be in KB rather than bytes.
Again, genuine code files do not usually come much larger than 500 KB, so if we keep seeing the sync byte for even around 5 packets, it should indicate a clear positive. But to err on the safe side, how about 188-byte intervals for the first 9.40 KB (fifty packets), then? This would take less than 1 ms per file, yet still have a very low chance of a false positive. Remember that we may not be talking just one MPEG-TS file here; someone may drop a whole folder of them into the project, so it's wise to be conservative about how much of each one we should be reading in, even if individually the read time might not be too long. |
@shirakaba I'm not sure where 188 KB packets came from? They're 188 Bytes; maybe you mean 10,000 x 188 Byte packets? I like your idea about using a limit. Isn't there already a parse limit of 1MB or am I confused? Why not just check up to the configured parse limit? |
@jon-valliere Good catch – you're right, I accidentally mistook packets to be in KB rather than bytes in my last comment, so I've corrected it with an edit now. Sorry for the confusion.
For non-TS files, the maximum program size is hard-limited to 20MB (Ryan Cavanaugh explains why shortly after the linked comment): #19326 (comment) For TS files, I can't find any mention of a parse limit. Here, someone even performs As now edited into my comment above, I have changed my suggested cautionary threshold from 10 packets to 50 packets, as this would keep read times for each file below 1 ms yet still provide a good amount of protection against false positives. Note: If anyone really does need to put a letter 'G' into their file both as the very first character and for every subsequent 188th character for 49 further iterations, then I would suggest a list of good alternatives to the letter 'G' here – Unicode characters based on 'G'. |
@shirakaba The compiler warning about "detection of MPEG-TS file /xxxxx/xxxx.ts" will also notify the user in the unlikely chance that they are attempting to compile a TypeScript file with 'G' in all the wrong places. That way they're not wondering, "why isn't this file compiling." |
My solution/work-around is quite simple:
Since there simply is a collision of file-extension conventions here, I don't see how any "real" solution can be found other than telling the compiler where your Typescript files really are and actually avoiding collisions. An alternative I could recommend would be using But you could also figure out quite easily if data is MPEG-TS in fact with the specific sync-bytes and headers and be pretty sure it's not a Typescript source. That would be much more elegant than a size-limit or such. |
@mhegazy Should this be probably done before |
MPEG-TS files consist of frames each 188 bytes long. These files should not be parsed as typescript files and therefore we look into the first 50 frames and check if we find a 'valid' header. Closes microsoft#21136
When using TS and hls at the same time avoid .ts extension for media chunk files. |
After #53667, I suspect that this is fixed as we should be bailing out early on these kinds of files. Is anyone still watching this issue that can verify 5.0 vs 5.1 on this front? |
TS Template added by @mjbvz
TypeScript Version: 4.3.5
Search Terms
From @jon-valliere on January 10, 2018 22:54
Steps to Reproduce:
The TypeScript processor should be smart enough to be able to detect if the file is text or not.
Copied from original issue: microsoft/vscode#41439
The text was updated successfully, but these errors were encountered: