microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
160.83k stars 28.21k forks source link

When I use vscode to open a folder, many empty file with invalid code automatically are generated. #145297

Closed na-an closed 2 years ago

na-an commented 2 years ago

Does this issue occur when all extensions are disabled?: Yes/No

howardlau1999 commented 2 years ago

Same issue here. Some empty files with random filenames are created when I open the folder using Remote SSH.

Some susceptible filenames seem like SQL.

Version: 1.65.2 (user setup) Commit: c722ca6c7eed3d7987c0d5c3df5c45f6b15e77d1 Date: 2022-03-10T14:33:55.248Z Electron: 13.5.2 Chromium: 91.0.4472.164 Node.js: 14.16.0 V8: 9.1.269.39-electron.0 OS: Windows_NT x64 10.0.19044

Remote OS is CentOS 7

daantimmer commented 2 years ago

Same issue here. Tried with all extensions disabled, same issue.

To make matters worse, some files are even modified to the point where the contents are erased. This happens in all sort of random files.

Seems to occur more often when building or configuring using, for example, cmake. But the severity of modified//added files is completely random.

I once had a filename that was about 100 characters long and looked like a string dump from a running process as it had a table 'look a like' string of characters.

Version: 1.65.2 (user setup) Commit: c722ca6c7eed3d7987c0d5c3df5c45f6b15e77d1 Date: 2022-03-10T14:33:55.248Z Electron: 13.5.2 Chromium: 91.0.4472.164 Node.js: 14.16.0 V8: 9.1.269.39-electron.0 OS: Windows_NT x64 10.0.19042

I have this happening on two unrelated machines.

zhanghb55 commented 2 years ago

I meet the same situation Version: 1.65.2 (Universal) Commit: c722ca6c7eed3d7987c0d5c3df5c45f6b15e77d1 Date: 2022-03-10T14:33:49.188Z Electron: 13.5.2 Chromium: 91.0.4472.164 Node.js: 14.16.0 V8: 9.1.269.39-electron.0 OS: Darwin x64 20.6.0

InvalidCode
daantimmer commented 2 years ago

I have just downgraded (by installing without uninstalling) 1.64.2, the issue persists

RenoirTan commented 2 years ago

Same issue here. I haven't been able to find out what exactly is the trigger but I know it's definitely caused by vs code because when I tried to write stuff using neovim or kate, these files don't appear.

From what I can tell, these files only appear in the root of the folder (and not in any subdirectories in the project). The names of these files are not valid unicode (e.g. \312\316\361 which is in octal is 11001010 11001110 11110001 in binary).

Screenshot_20220317_161207 Screenshot_20220317_161226

System Info

CPUs 11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz (16 x 1091)
GPU Status 2d_canvas: enabled gpu_compositing: enabled multiple_raster_threads: enabled_on oop_rasterization: disabled_off opengl: enabled_on rasterization: disabled_software skia_renderer: enabled_on video_decode: disabled_software vulkan: disabled_off webgl: enabled webgl2: enabled
Load (avg) 2, 2, 1
Memory (System) 15.41GB (2.78GB free)
Process Argv --no-sandbox --unity-launch --crash-reporter-id 7f52dc70-39d5-4913-96f6-32ae4ae5e9d4
Screen Reader no
VM 0%
OS Linux x64 Kernel version 5.16.14

Extensions

Extension Author (truncated) Version
better-comments aar 2.1.0
codesnap adp 1.3.4
vscode-django bat 1.10.0
toml be5 0.6.0
doxdocgen csc 1.4.0
python-environment-manager don 1.0.3
python-extension-pack don 1.7.0
gitlens eam 12.0.4
go gol 0.32.0
helium-icon-theme hel 1.0.0
better-cpp-syntax jef 1.15.13
vsc-python-indent Kev 1.14.2
rust-analyzer mat 0.2.975
git-graph mhu 1.30.0
fluent-icons mig 0.0.17
vscode-docker ms- 1.20.0
python ms- 2022.2.1924087327
vscode-pylance ms- 2022.3.2
jupyter ms- 2022.2.1030672458
jupyter-keymap ms- 1.0.0
jupyter-renderers ms- 1.0.6
remote-containers ms- 0.224.2
remote-ssh ms- 0.76.1
remote-ssh-edit ms- 0.76.1
remote-wsl ms- 0.64.2
vscode-remote-extensionpack ms- 0.21.0
cmake-tools ms- 1.9.2
cpptools ms- 1.9.4
cpptools-extension-pack ms- 1.1.0
autodocstring njp 0.6.1
glassit s-n 0.2.4
cmake twx 0.0.17
vscodeintellicode Vis 1.2.17
jinja who 0.0.8
daantimmer commented 2 years ago

From what I can tell, these files only appear in the root of the folder (and not in any subdirectories in the project).

This statement is incorrect. I get original files being emptied in my build tree and get files named cpp.hint in my build tree

edit: I've just got a file name cpp.stop image

howardlau1999 commented 2 years ago

Seems like if you are using Remote SSH, you can temporarily resolve the issue by deleting ~/.vscode-server and reopening VSC. I don't know if the same issue would happen again.

daantimmer commented 2 years ago

For me personally I am not using Remote SSH.

daantimmer commented 2 years ago

Additional information. The deletion of contents of files was not restricted to my working folder!

It has even managed to delete contents outside this folder, for example my 'windows kits' has been destroyed and I don't know to what extend, but the following file, for example, is completely empty now:

image

I do not know if the issue is only affecting parsing of 'include' files or that it could possibly have touched completely unrelated files as well.

A few more files were affected: image

Searched on size 0, modified today

WoodsCumming commented 2 years ago

image image This preview introduces this bug.

daantimmer commented 2 years ago

This preview introduces this bug.

How would this explain that the issues persisted with all extensions disabled?

WoodsCumming commented 2 years ago

This preview introduces this bug.

How would this explain that the issues persisted with all extensions disabled?

image Switching to the official release solves this problem temporarily.

kblackcn commented 2 years ago

In my case, I disable all extensions and restart vscode. Files are generated just after reenabling cpptools.

Maybe there are still running process in the background or so. After I rollback to release branch, the problem just goes away.

I'm also suspecting the file-deletion issue ruined my dev docker twice. I found many header files become zero-sized and even pthread won't work.

bpasero commented 2 years ago

I wonder if this issue is being caused by an installed extension. Can you try to run VS Code without extensions? From the command line (NOT the integrated terminal in Code), execute: code --disable-extensions and try your steps again to see if it reproduces. If you see it is an issue with the extension, please file it against the extension repository itself.

sbovbjerg commented 2 years ago

I traced this to 1.9.4 pre-release of the C/C++ extension. I can trigger the problem when there are updates to the files in the project folder. With all extension disabled the problem goes away. The problem also goes away if I switch to the release version (1.8.4)

gev commented 2 years ago

node-ipc?

spartanatreyu commented 2 years ago

Man, I can't wait to read the blog post explaining what happened here

mhavill commented 2 years ago

This bug has caused ripples through the PlatformIO community in the last 24 hours.

Can anyone tell me how I picked up this pre-release this morning without knowing? I would not be knowing running any pre-release of software (I have enough problems of my own creation! ) - Has it automatically deployed everywhere?

spartanatreyu commented 2 years ago

Can anyone tell me how I picked up this pre-release this morning without knowing?

I recall seeing someone on reddit say they thought it was because they installed the language extension while it was still in pre-release. After some time had passed, the extension officially released, however vscode still had them marked down as pre-release, so it kept installing the new pre-release versions, which eventually led to some of their files becoming corrupted today.

wangym307 commented 2 years ago

c/c++ extension v1.9.4 's problem.
https://github.com/microsoft/vscode-cpptools/issues/9046

hello-smile6 commented 2 years ago

After some time had passed, the extension officially released, however vscode still had them marked down as pre-release

Is that a bug?

mhavill commented 2 years ago

Is that a bug?

@hello-smile6 I would guess so!

they installed the language extension while it was still in pre-release. Thank you @spartanatreyu. Unfortunately, I don't believe that to be the case in my situation.

Perhaps @sean-mcmanus can help us understand how this has happened? (I recall seeing that there had been about 29k downloads of the update this morning - that is a big widespread impact!)

ATM, I am not convinced that there has not been a wider impact on my environment.

hello-smile6 commented 2 years ago

Is that a bug?

@hello-smile6 I would guess so!

they installed the language extension while it was still in pre-release. Thank you @spartanatreyu. Unfortunately, I don't believe that to be the case in my situation.

  • I only loaded the extension less than 8 months ago and I think this extension well proceeded that
  • I am old enough to know not to risk pre-release software
  • It doesn't explain how duff code got into a release (albeit 'pre-release')
  • it doesn't explain how it deployed to my environment this morning without my activation. Reading the VSC documentation I cannot find anything that would enable auto updates of extensions, and in fact the sync function implies that there is not an auto update function (IMO).

Perhaps @sean-mcmanus can help us understand how this has happened? (I recall seeing that there had been about 29k downloads of the update this morning - that is a big widespread impact!)

ATM, I am not convinced that there has not been a wider impact on my environment.

As far as I understand, vscode automatically updates extensions.

sean-mcmanus commented 2 years ago
mhavill commented 2 years ago

Thank you @sean-mcmanus My experience was more that

  • None of us on our team have been able to repro the issue so far on multiple machines and projects. We have not identified what factor causes the repro.

I could see if I can re-produce it!

hello-smile6 commented 2 years ago

I'm glad I have absolutely no knowledge of C++ and and barely any of C, and don't have that extension installed. I routinely open application install directories using vscode.

mhavill commented 2 years ago

As far as I understand, vscode automatically updates extensions.

That would be very worrying if so, particularly if it switches you from a release version to a pre-release version! https://code.visualstudio.com/docs/editor/settings-sync To me this implies that updates are not automatic (or they would override your Sync preferences) Does anyone have contrary documentation?

sean-mcmanus commented 2 years ago

@mhavill You have to opt-in to pre-release version and there's and extenions.autoUpdate setting for disabling extension updates.

hello-smile6 commented 2 years ago

For reference: https://github.com/microsoft/vscode-cpptools/issues/9041#issuecomment-1071991779

mhavill commented 2 years ago

I have searched in the .platformio\packages folder and there were 118 files modified in a couple of minutes around 6:20 am. I have replaced about 90%. They were all in toolchains or frameworks but there were a variety of file types - .exe, .h, .cpp, .hint , .stop

Looks like it only smashed the projects I had open at the time, but it not only dropped new files, it also hit some .h, .hint , .stop and .txt files

I'm still searching across the whole of the drive - this caught my eye as it seems to be the time when the update happened image

I cannot see anything significant in Event Viewer although it is not one of my strong areas.

sean-mcmanus commented 2 years ago

@mhavill We've finally found the repro and a fix for the root issue for our pending 1.9.6 release. We're very sorry for any problems this may have caused and our looking into various things that could potentially prevent this from happening again.

mhavill commented 2 years ago

Thank you @sean-mcmanus - believe me - I am absolutely delighted that you have found this - The alternative would point (in my mind) to some security attack/breach.

I don't know if anything provided helped, but I would be more than happy to be involved in forensics on these matters. I have a long history in safety critical systems and high value financial services, so I do get twitchy when the unexplained happens and I strive to get to the root cause.

Have a great day (if there is any left!)

sean-mcmanus commented 2 years ago

Yeah, there was no security attack or breach -- just an accidental usage of uninitialized memory from a modification to an external third party subsystem that doesn't follow modern C++ coding guideline that could have prevented or detected usage of uninitialized pointers (like our main code base does).

daantimmer commented 2 years ago

Yeah, there was no security attack or breach -- just an accidental usage of uninitialized memory from a modification to an external third party subsystem that doesn't follow modern C++ coding guideline that could have prevented or detected usage of uninitialized pointers (like our main code base does).

Oof, that sounds like a deep deep deeeeeep rabbit hole to find. Good on finding though!

daantimmer commented 2 years ago

Can anyone tell me how I picked up this pre-release this morning without knowing?

I recall seeing someone on reddit say they thought it was because they installed the language extension while it was still in pre-release. After some time had passed, the extension officially released, however vscode still had them marked down as pre-release, so it kept installing the new pre-release versions, which eventually led to some of their files becoming corrupted today.

That was me. I've had my installation for the past 4 years :-). Even the 'insiders' configuration in my settings file was still there from a long long time ago. For me the insiders setting carried over, I guess, to the pre-release version of the 'new new way' that extensions were updated.

But then again, this issue could easily, as it sounds, have slipped in a proper released version. So, sometimes shit just hits the fan.

sean-mcmanus commented 2 years ago

@daantimmer I don't believe this bug would've made it into the non-pre-release builds, because we have a policy of shipping changes to the pre-release version first and then releasing into the non-pre-release after things seem okay after a few days...with "last minute" changes generally only occurring if we believe it's a low risk fix.

daantimmer commented 2 years ago

@daantimmer I don't believe this bug would've made it into the non-pre-release builds, because we have a policy of shipping changes to the pre-release version first and then releasing into the non-pre-release after things seem okay after a few days...with "last minute" changes generally only occurring if we believe it's a low risk fix.

I was not trying to imply that this specific bug could have slipped through. Was trying to imply that nobody is ever perfect and mistakes can happen. Even on a thoroughly tested release. "Looking at you, any random game development studio" :-)

TavakoliAli commented 2 years ago

Hello Due this bug the content of one of my source file which had 3000 line, was deleted . I don't use version control system. How can i restore it?

sean-mcmanus commented 2 years ago

@TavakoliAli Unfortunately, there is no way to restore the file (as far as I know). You should consider using a source control system such as git, cloud storage backup, etc.. Using the non-pre-release version of the C/C++ extension (1.8.4) would also be recommended. File deletion/corruption bugs are pretty rare. That last one we had was a couple years ago during code formatting in a multi-root workspace (https://github.com/microsoft/vscode-cpptools/issues/1073). In fact, we still have a bug where formatting on a symlinked workspace folder can corrupt files (https://github.com/microsoft/vscode-cpptools/issues/5061), which has a root cause of https://github.com/microsoft/vscode-cpptools/issues/4573.

mhavill commented 2 years ago

@sean-mcmanus , @hello-smile6 - thank you Indeed the default setting in VSC is enabled! image Wow! That seems pretty dangerous! I don't know what controls are put over the Extension Marketplace but we have just seen a small example of a change that happened invisibly and caused widespread confusion. My config is now changed from default to 'None'
I can't prove it but I don't believe I opted into the pre-release version. Is there any log of Extension updates in VSC?

mhavill commented 2 years ago

Due this bug the content of one of my source file which had 3000 line, was deleted .

This is the first post that mentions deletion of source files? Are there other examples? So far I have detected in my system:

daantimmer commented 2 years ago

Due this bug the content of one of my source file which had 3000 line, was deleted .

This is the first post that mentions deletion of source files? Are there other examples? So far I have detected in my system.

I've had source and header file contents deleted. Both in source control, but also in my windows SDK installation. I've mentioned this here and there as well :-)

hello-smile6 commented 2 years ago

@sean-mcmanus , @hello-smile6 - thank you Indeed the default setting in VSC is enabled! image Wow! That seems pretty dangerous! I don't know what controls are put over the Extension Marketplace but we have just seen a small example of a change that happened invisibly and caused widespread confusion. My config is now changed from default to 'None' I can't prove it but I don't believe I opted into the pre-release version. Is there any log of Extension updates in VSC?

Should be in /var/log or something.

mhavill commented 2 years ago

Should be in /var/log or something.

Sounds like Linux? not Windows 10?

hello-smile6 commented 2 years ago

Should be in /var/log or something.

Sounds like Linux? not Windows 10?

Then try C:\Windows\system32\drivers\var\log or wherever logs would be stored.

mhavill commented 2 years ago

Ah - if only Windows and Windows developers were so consistent!

No such logs and I cannot find anything in Google searches. Perhaps @sean-mcmanus can let us know if there is such for logging installations/updates in VSC?

hello-smile6 commented 2 years ago

Ah - if only Windows and Windows developers were so consistent!

No such logs and I cannot find anything in Google searches. Perhaps @sean-mcmanus can let us know if there is such for logging installations/updates in VSC?

Maybe use a VM and wine?

sean-mcmanus commented 2 years ago

@mhavill I'm not familiar with any logging in regards to installation of extensions (someone on the VS Code team might know). I know that prior to VS Code's pre-release feature we had our own custom C_Cpp.updateChannel "Insiders" setting, so if you had that setting set somehow, then you got auto-migrated to the VS Code's new pre-release mechanism and we had a dialog box that appeared that prompted users to switch to the Insiders build, so you may have clicked that.

mhavill commented 2 years ago

Thanks @sean-mcmanus. Maybe someone will pick it up in the future!? I won't disturb you more. My system is all back to normal with no major impact.

"Insiders" setting, so if you had that setting set

I am most definitely an outsider not an insider :) It'll be a mystery.

TavakoliAli commented 2 years ago

Due this bug the content of one of my source file which had 3000 line, was deleted .

This is the first post that mentions deletion of source files? Are there other examples? So far I have detected in my system:

So i have all problems you mentioned. I rewrote header and deleted null files but i don't have enough time to rewrite source file.