Skip to content
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

Prevent opening files that are too large #4731

Closed
502647092 opened this issue Mar 27, 2019 · 8 comments · Fixed by #8152
Closed

Prevent opening files that are too large #4731

502647092 opened this issue Mar 27, 2019 · 8 comments · Fixed by #8152
Assignees
Labels
editor issues related to the editor enhancement issues that are enhancements to current functionality - nice to haves

Comments

@502647092
Copy link
Contributor

502647092 commented Mar 27, 2019

Description

when i click a tar.gz file on explorer
theia is crash
i think we need add warn when open large file

Reproduction Steps

create a large file
click on explorer

OS and Theia version:
latest next version

Diagnostics:

root INFO [nsfw-watcher: 11220] Started watching: /home/project/go.tgz

<--- Last few GCs --->

[12:0x3a2d0d0] 178207033 ms: Mark-sweep 1255.3 (1313.2) -> 1254.7 (1325.7) MB, 127.7 / 0.0 ms  allocation failure GC in old space requested
[12:0x3a2d0d0] 178207110 ms: Mark-sweep 1254.7 (1325.7) -> 1254.6 (1294.7) MB, 76.3 / 0.0 ms  last resort GC in old space requested
[12:0x3a2d0d0] 178207164 ms: Mark-sweep 1254.6 (1294.7) -> 1254.6 (1294.2) MB, 54.7 / 0.0 ms  last resort GC in old space requested

root WARN Couldn't restore widget state for debug-console. Error: TypeError: Cannot read property 'getControl' of undefined 
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: node::Abort() [/usr/local/bin/node]
 2: 0x8ccf9c [/usr/local/bin/node]
 3: v8::Utils::ReportOOMFailure(char const*, bool) [/usr/local/bin/node]
 4: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/usr/local/bin/node]
 5: v8::internal::Factory::NewRawTwoByteString(int, v8::internal::PretenureFlag) [/usr/local/bin/node]
 6: v8::internal::String::SlowFlatten(v8::internal::Handle<v8::internal::ConsString>, v8::internal::PretenureFlag) [/usr/local/bin/node]
 7: v8::internal::String::Flatten(v8::internal::Handle<v8::internal::String>, v8::internal::PretenureFlag) [/usr/local/bin/node]
 8: v8::String::WriteUtf8(char*, int, int*, int) const [/usr/local/bin/node]
 9: node::StringBytes::Write(v8::Isolate*, char*, unsigned long, v8::Local<v8::Value>, node::encoding, int*) [/usr/local/bin/node]
10: node::Buffer::New(v8::Isolate*, v8::Local<v8::String>, node::encoding) [/usr/local/bin/node]
11: 0x8e9444 [/usr/local/bin/node]
12: 0x3bf5066b9a87

<--- JS stacktrace --->

==== JS stack trace =========================================

Security context: 0x3926efd258b9 <JSObject>
    1: fromString(aka fromString) [buffer.js:~298] [pc=0x3bf5066dbf3c](this=0x35839aa022d1 <undefined>,string=0x2a17749d3569 <Very long string[257689628]>,encoding=0x35839aa022d1 <undefined>)
    2: from [buffer.js:177] [bytecode=0x2e7e00b5ad1 offset=11](this=0x8151f4ae989 <JSFunction Buffer (sfi = 0x3926efd7da69)>,value=0x2a17749d3569 <Very long string[257689628]>,encodingOrOffset=0x35839aa022d...
@akosyakov akosyakov added the enhancement issues that are enhancements to current functionality - nice to haves label Mar 27, 2019
@akosyakov
Copy link
Member

Something like in VS Code would be nice:
Screen Shot 2019-03-27 at 05 40 09

@akosyakov akosyakov added help wanted issues meant to be picked up, require help editor issues related to the editor labels Mar 27, 2019
@kittaakos
Copy link
Contributor

Related: #1470?

@akosyakov
Copy link
Member

no, #1470 is about replicating document buffers on the backend for quick access from LS and VS Code extensions for example

@sauny
Copy link
Contributor

sauny commented Jul 8, 2019

@akosyakov Thought I would look at this as it has been around for a while.

I can't find a way of injecting a piece of text (to replicate the vscode way of working) into the open function here:
https://github.com/theia-ide/theia/blob/7fe439a30d53846a82d6b0c916de5a69b9da2c77/packages/editor/src/browser/editor-manager.ts#L104-L108

Any ideas?

@akosyakov
Copy link
Member

akosyakov commented Jul 9, 2019

I don't think that it is so easy. We probably need a new open handler which has a priority greater than EditorManager. It should check whether the given URI is a file URI and check its size. If it is greater than the certain threshold then it should hit and show the custom widget, i.e. FileTooLargeWidget and FileTooLargeOpenHandler. It should go to the filesystem extension then, since it does not have a dependency to the editor extension.

For Do you want to open it anyway? such widget should call OpenerService with the special options indicating that FileTooLargeOpenHandler should skip, then the editor manager will hit.

Is it clear?

@sauny
Copy link
Contributor

sauny commented Jul 9, 2019

Clear... whether I can do it or not remains to be seen... I will give it a go!

@sauny
Copy link
Contributor

sauny commented Jul 10, 2019

I have managed to create the OpenHandler but I have no idea on how to create the Widget and get it called... is there any documentation on this at all?

@akosyakov
Copy link
Member

@sauny Please have a look for examlpe at EditorWidget. You need a WidgetFactory create instances and then use WidgetManager to call a factory with some options. Your OpenHandler probably should inherit NavigatableOpenHandler that widgets play nicely with file renaming/deletion and get expanded in the navigator.

@akosyakov akosyakov self-assigned this Jul 8, 2020
@akosyakov akosyakov removed the help wanted issues meant to be picked up, require help label Jul 8, 2020
akosyakov added a commit that referenced this issue Jul 8, 2020
Signed-off-by: Anton Kosyakov <anton.kosyakov@typefox.io>
akosyakov added a commit that referenced this issue Jul 9, 2020
Signed-off-by: Anton Kosyakov <anton.kosyakov@typefox.io>
akosyakov added a commit that referenced this issue Jul 28, 2020
Signed-off-by: Anton Kosyakov <anton.kosyakov@typefox.io>
akosyakov added a commit that referenced this issue Aug 3, 2020
Signed-off-by: Anton Kosyakov <anton.kosyakov@typefox.io>
akosyakov added a commit that referenced this issue Aug 3, 2020
Signed-off-by: Anton Kosyakov <anton.kosyakov@typefox.io>
akosyakov added a commit that referenced this issue Aug 3, 2020
Signed-off-by: Anton Kosyakov <anton.kosyakov@typefox.io>
minyoungyang pushed a commit to minyoungyang/theia that referenced this issue Aug 4, 2020
Signed-off-by: Anton Kosyakov <anton.kosyakov@typefox.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
editor issues related to the editor enhancement issues that are enhancements to current functionality - nice to haves
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants