• Login
Community
  • Login

Fix corrupted txt file (NULL)

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
corruptedfixtextnullfile
114 Posts 37 Posters 144.4k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M
    Mark Cage
    last edited by Aug 3, 2018, 9:40 AM

    That sucks! i hadn’t turned back up on before this happened . Also use the save key all the time. But the null error still occurred. Can only pray that it doesn’t happen again :)

    1 Reply Last reply Reply Quote 0
    • L
      Lucky Erumebor
      last edited by Aug 5, 2018, 10:27 PM

      same thing just happened to me… v7.5.8

      1 Reply Last reply Reply Quote 0
      • C
        Claudia Frank
        last edited by Aug 21, 2018, 8:21 PM

        Gotcha!!

        Hopefully I can reproduce it under debugger.

        Cheers
        Claudia

        1 Reply Last reply Reply Quote 4
        • J
          Jeremy Jordan
          last edited by Aug 22, 2018, 11:11 PM

          yeah but this is more corrupted because my txt file named Oofood instead of saying words… it came up with this: ¶¬®°~Z…yàãñöpý²Ã”¦ Vš¸:lŸã"Œ7$2¥‰+s;¡*p“‘A\ìö© /2[ÐnUû“H–™øk´­b|Ë*Y÷T¾t=¥t˜»¤RÞ~YP6*•°ÉÜü´ÄZ¤ï°³Ê}=ƒ0såÁ¨,©°¯Îß”1XŽÁb€(Þ}Y4ýµB™yª
          @¶e§‹Ê ©öà[_dy ‘rü±wD˜ŒíÝP ÉïCŸ;Q¬|it³JÔÈX5[7Dë¹ã!ä•0ynöWª@»C²É;]C„rÏ<õª—$5ûUôdx3×2`ö¦3õÆš&ÛgpÖǝ$³:Þ"АµÙ&¹ŠQâ‚zg¾ðõ^5öŽ(^³Eð«N\§DFNi†“»©˜.Ù/ã« &æ-”&ÚÏŠû²š¢ÔÿÐØ0\m;B–@8ÍÛv¶ïË‘®xJU ´ ôP
          
          ’Ð 6ÝÁ¤ªÀ½4;X¶y•kÕñ”ø¡ÇéVËè×_ýÔÇ9|E’Xújƒ /6O´ûv øEî\ê±s5T)%,T,Âa†L c£"ÇÕz ˆ ¯îêjøRÖÓ:òo›7ÆÓGmyEU¶Xo‘Å«·øÈëJõ¾Äwå¦B<\©¶ÖÙâÎ,@´~_Nä&BkBc&AŽ…Zºc

          C 1 Reply Last reply Aug 23, 2018, 12:14 PM Reply Quote 0
          • C
            Claudia Frank @Jeremy Jordan
            last edited by Aug 23, 2018, 12:14 PM

            @Jeremy-Jordan

            but this looks like the file content has been replaced with binary data - hard to believe that npp is responsible for that.
            I assume that your issue must be caused by something else.

            Cheers
            Claudia

            1 Reply Last reply Reply Quote 1
            • P
              PeterJones
              last edited by Aug 23, 2018, 1:50 PM

              @Jeremy-Jordan,

              As @Claudia-Frank said, that’s binary data, not just NULLs. If that’s really happened to a file that was plain text, you’ve either edited it with some other editor which has encoded it, or the file has been encrypted. If you weren’t expecting the file to be encrypted, then there’s (unfortunately) a very high probability you’ve been infected with a virus, ransomware, or other malware. Please run a reputable scanner ASAP.

              Since many forms of viruses, ransomware, and other malware make your data unrecoverable, I am hoping you have a separate backup of any essential data. But don’t try to access that backup until you know the computer you are on is clean – I’d hate for your backup to become infected as well.

              1 Reply Last reply Reply Quote 2
              • M
                Michael Simcich
                last edited by Aug 27, 2018, 6:15 PM

                I have an interesting variation on a theme to report. Yesterday I worked most of the day on a set of text files; some xls files, and asp.net files loaded into visual studio. Most work was done by 9 pm; I had saved those files many times during the day’s work. At about 11:30 pm the pc became increasingly unresponsive and eventually I had to reset it. The pc booted normally. I left it on all night so that the daily Acronis backup, which seemed to have stalled in the evening (and may have been the source of the system failure) could do it’s thing.

                This AM I found that all of those files (.net, .xls, .txt in notepad++) were corrupted, with the text and .net files showing as NULL everywhere. I don’t have Backup on Save turned on. Session snapshot and periodic backup are on, probably default settings as I’ve never known about np++ backup features before today, but there are no recent files in that dir. I have various types of backups to fall back on.

                But the main reason I’m posting this is that the NULL blowout happened to other files that were not in use by notepad++. I personally don’t recall ever having file data losses like this before, ever; but it doesn’t seem to be true that it’s an issue with notepad++, or at least only notepad++.

                C 1 Reply Last reply Aug 28, 2018, 11:49 AM Reply Quote 2
                • C
                  Claudia Frank @Michael Simcich
                  last edited by Claudia Frank Aug 28, 2018, 11:51 AM Aug 28, 2018, 11:49 AM

                  @Michael-Simcich

                  you are right, this issue can happen with any software if the requirements are fulfilled.
                  Basically it is this, a thread has opened the file and then something happens which forces
                  the operating system to kill the process. In this situation a thread might not be able to close
                  the file correctly which then results in a corrupted file.

                  I’m able to reproduce this with a 32bit npp version and file around ~100MB where backup is enabled and
                  the system is under load. If, for example, I would convert everything to uppercase,
                  under this condition, ~1 out of 10 times npp freezes, dies and backup file only is corrupted.
                  But if you restart npp, then it looks like the real file is corrupted, just because npp loaded the backup file as it wasn’t saved correctly at this time.
                  Unfortunately I wasn’t able to reproduce this behavior running npp under the debugger and
                  haven’t found out yet whether the cpu, memory or io load or a combination of those is needed
                  to reproduce it. This happens, for me, only on a 32bit version of npp with activated backup,
                  on a 64bit version I was not able to reproduce this behavior, even with larger files. Tested with 1GB.

                  Cheers
                  Claudia

                  M 1 Reply Last reply Aug 28, 2018, 1:58 PM Reply Quote 4
                  • P
                    pnedev
                    last edited by Aug 28, 2018, 12:46 PM

                    Hi @Claudia-Frank ,

                    Very good analysis indeed.
                    Can I ask you to test your failing scenario with a test build of mine?
                    It is the official v7.5.8 but with a fix I did on the locking mechanics of the file during backup. Here is the 32-bit binary:
                    https://ci.appveyor.com/api/buildjobs/bjaisvrte85g4o0a/artifacts/Notepad%2B%2B.Win32.Unicode Release.exe

                    Thank you for trying this and writing back, I appreciate it.

                    BR

                    C 2 Replies Last reply Aug 28, 2018, 12:50 PM Reply Quote 2
                    • C
                      Claudia Frank @pnedev
                      last edited by Aug 28, 2018, 12:50 PM

                      Hi @pnedev

                      Thx for the build, I will do the test later today - need to go to work soon.

                      Cheers
                      Claudia

                      1 Reply Last reply Reply Quote 2
                      • M
                        Michael Simcich @Claudia Frank
                        last edited by Aug 28, 2018, 1:58 PM

                        @Claudia-Frank thanks for that clear explanation.

                        1 Reply Last reply Reply Quote 1
                        • C
                          Claudia Frank @pnedev
                          last edited by Claudia Frank Aug 28, 2018, 11:15 PM Aug 28, 2018, 11:14 PM

                          @pnedev

                          I found this file from this issue thread and it seems that this file can be used to confirm that the backup is the culprit.
                          Unfortunattely your build is crashing also when doing the trim trailing spaces action.
                          I’m currently running some tests like doing it 100 times in a row and 100 times after restart npp … to see if this is really the case.

                          The test file is a bit unusual as I described in the issue thread and needs to be investigated as well
                          but at least it looks like there is a reliable way to crash npp and therefore a chance to find out what it is causing it.
                          Whether or how NULL backup files are involved can’t be said at the moment.

                          Cheers
                          Claudia

                          1 Reply Last reply Reply Quote 2
                          • P
                            pnedev
                            last edited by Aug 29, 2018, 7:22 AM

                            Hi @Claudia-Frank ,

                            Thanks for trying and for pointing to that file.
                            I can do some tests on my own now.

                            BR

                            1 Reply Last reply Reply Quote 1
                            • P
                              pnedev
                              last edited by Aug 29, 2018, 9:22 AM

                              OK, I think I got what the problem is.
                              This is the cause for the problem in this issue as well.

                              Backup is running in a separate thread as can be seen in Notepad_plus.cpp, void Notepad_plus::launchDocumentBackupTask() .
                              What it does is periodically executing Buffer.cpp, bool FileManager::backupCurrentBuffer() .

                              Now imagine that we launch a long-running operation in Notepad++ from the user thread.
                              While it is running and doing its processing on the Scintilla buffer the periodic backup thread kicks.
                              The bool FileManager::backupCurrentBuffer() is called which GETS THE RAW SCINTILLA BUFFER POINTER here:

                              FILE *fp = UnicodeConvertor.fopen(fullpath, TEXT("wb"));
                              if (fp)
                              {
                              int lengthDoc = _pNotepadPlus->_pEditView->getCurrentDocLen();
                              char* buf = (char*)_pNotepadPlus->_pEditView->execute(SCI_GETCHARACTERPOINTER); //to get characters directly from Scintilla buffer

                              Now backup can be written at once or in portions depending if WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance() conversions are needed BUT anyway:

                              WHILE BACKUP FILE IS BEING WRITTEN FROM THE RAW SCINTILLA BUFFER,
                              THE SCINTILLA BUFFER ITSELF IS BEING UPDATED BY THE USER LONG RUNNING OPERATION THREAD (THIS MIGHT EVEN INCLUDE BUFFER RELOCATION IF MORE MEMORY ALLOCATION IS NEEDED).

                              I’ll have to figure out a proper way to fix that now.

                              1 Reply Last reply Reply Quote 4
                              • P
                                pnedev
                                last edited by Aug 29, 2018, 11:03 AM

                                One update:

                                The bool FileManager::backupCurrentBuffer() properly locks LongRunningOperation so the concurrent Scintilla buffer access shouldn’t happen during backup but it seems it still does. Which means the LongRunningOperation lock is not done properly for Trim trailing spaces and Find and Replace in Files and probably in other places.

                                1 Reply Last reply Reply Quote 2
                                • P
                                  pnedev
                                  last edited by Aug 29, 2018, 11:47 AM

                                  Hi again @Claudia-Frank ,

                                  Could you please try again with this binary:
                                  https://ci.appveyor.com/api/buildjobs/3tfm2eeubr9hg9y9/artifacts/Notepad%2B%2B.Win32.Unicode Release.exe ?

                                  It has fix for Trim trailing spaces and I cannot reproduce the issue on my side anymore.
                                  Sorry to bother you again, I appreciate your help.

                                  BR

                                  C 1 Reply Last reply Aug 29, 2018, 1:18 PM Reply Quote 2
                                  • C
                                    Claudia Frank @pnedev
                                    last edited by Aug 29, 2018, 1:18 PM

                                    Hi @pnedev

                                    Sorry to bother you again, I appreciate your help.

                                    No problem, if I can be of any help I will do so but same as yesterday, I will do the test later today.
                                    I’m on late shift this week.

                                    Cheers
                                    Claudia

                                    1 Reply Last reply Reply Quote 2
                                    • P
                                      pnedev
                                      last edited by Aug 29, 2018, 3:07 PM

                                      Hi again @Claudia-Frank ,

                                      I have made official pull request addressing the issue:
                                      https://github.com/notepad-plus-plus/notepad-plus-plus/pull/4803 .

                                      The corresponding x86 binary is:
                                      https://ci.appveyor.com/api/buildjobs/p3t4vsd8lj202wjm/artifacts/Notepad%2B%2B.Win32.Unicode Release.exe .

                                      This needs to be thoroughly tested though as it changes the way backup is performed.
                                      I hope it fixes the file corruption problems observed so far but only time will tell.

                                      Thank you.

                                      BR

                                      C 2 Replies Last reply Aug 29, 2018, 3:31 PM Reply Quote 4
                                      • C
                                        Claudia Frank @pnedev
                                        last edited by Claudia Frank Aug 29, 2018, 3:33 PM Aug 29, 2018, 3:31 PM

                                        Hi @pnedev

                                        I’m currently thinking of the using the test file and add additional data to fulfill
                                        the requirements for all modification actions like find/replace, trim, convert case …
                                        basically what can be done using edit/search/view menu (encoding menu I’m unsure atm??)

                                        Then I run each action to see that if it crashes npp with the original npp binary and your build.
                                        Afterwards I’m doing long running test which means each action do get executed 100 times
                                        in a row and a following test of 1000 random actions in a row.

                                        I will be using python script plugin as the only additional plugin and the test would be something like

                                        while counter < 100
                                            notepad.menuCommand(ACTION_ID)
                                            editor.undo()
                                        

                                        and modified for having 1000 iterations with random ACTION_ID

                                        I know, having an additional plugin loaded might have impact on the test itself but
                                        if the result is success then it should be ok. If not I do it manually with minimum npp setup.

                                        What do you think?
                                        @all - any additional ideas?

                                        Cheers
                                        Claudia

                                        1 Reply Last reply Reply Quote 2
                                        • C
                                          Claudia Frank
                                          last edited by Aug 29, 2018, 3:35 PM

                                          A test to see if the backup file gets created correctly is needed too.

                                          Cheers
                                          Claudia

                                          1 Reply Last reply Reply Quote 2
                                          • First post
                                            Last post
                                          The Community of users of the Notepad++ text editor.
                                          Powered by NodeBB | Contributors