I released a word processor formatting the hard drive after every 1024th save

Telling beginner storytellers about how you once seriously screwed up is a good way to help them deal with impostor syndrome .

It was probably 1984-1985. Then I was a 25-year-old budding programmer with five years of experience. I and another programmer wrote and supported a set of applications similar to today's Office: spreadsheets, word processor, database, plotter, etc. We set up this whole system for three to four vertical markets [ highly specialized business clients / approx. perev. ].

I wrote most of the word processor myself. I wrote at Fort, and for various combinations of OSes and processors. Young people are not familiar, but in those days, new microcomputers with their own special OS and one of several processor options came out every few months.

Fort used the exchange of block data with the disk. Each block had a length of 1 kb, and in order to save something more than 1 kb, it was necessary to work with the master block of the file, where the offsets of all blocks with data were stored - in fact, it was a couple of lists of occupied and unoccupied blocks.

To initialize this master block, it had to be filled with zeros. Well, it started. In short, I changed the application so that it supported files twice as large as before - and instead of 256 elements in the master block, 1024 appeared.

Each entry took up - attention - one word from 16 bits. Therefore, if 512 words still fit into my 1 kb master block, then 1024 words already required the use of two blocks.

Therefore, I changed the number of blocks filled with zeros, but I did not change the buffer size. And when you work with unprotected memory, and you write 2048 zeros in the space of 1024 bytes, the remaining bytes will overwrite any random garbage that they find in memory.

In my case, any random garbage turned out to be the master block of the OS disk. Yes ... And when I initialized a new file, which happened every 1024th time when writing a one-block file, I overwritten the master block of the disk, which deleted all files from it.

And we, of course, released this version, which worked for 8-9 weeks. And you can imagine the number of calls from customers that we had to receive. In the end, we advised everyone to keep backups (which was done, by the way, using video tapes) every single day.

I spent many weeks just apologizing over the phone while running my program in the debugger again and again. And I didn’t succeed. Nothing.

And then one woman called and described in colorful terms - and she worked in freight transport, so I now actively use her examples from the field of profanity - that she made a backup copy, launched a word processor, and he immediately cleaned her disk. She downloaded the backup again, and the processor again immediately erased her disk. She was furious.

And, imagine, it took me two whole hours to understand how lucky I was. I told this story to my colleague at dinner, and then it dawned on me - stop. Stop. At once? Everytime?

I called her and promised all the earthly blessings, if only she would pack this cassette and send it to us. I promised her to pay the shipping costs and cancel the monthly payments for our services (my boss did not hesitate for a second: “Yes, hell, we will cancel her payments”).

And finally, I was able to reproduce this error. And she did not cheat. That backup that she saved turned out to be at a critical point: 1023 backups at the time of creation. Download the backup, save the file, and the drive is guaranteed to be cleaned.

Maybe I'm exaggerating, but, in my opinion, I found the problem the same morning when we got the film. It was so easy to find in the debugger.

I looked at a 2 kb block that was supposed to be written, and the last 1 kb was filled with some kind of garbage. It seemed strange to me, and I began to understand. And, of course, it was not garbage - it was 1024 bytes of the disk master block that the OS stored next to my file master block.

I got a backup copy of the “before” the kernel - I did not have a core dump, but it gave me a guaranteed way to get to this defect. If I were not lucky, I would not have found him. I would simply not have guessed that I was writing not in my memory, but in the system.

So, yes - your “master” geek has released a word processor, which within eight to nine weeks has formatted the client’s hard drive after every 1024th save. Because, well, I'm a craftsman.

You can find a lot of morality in this story, but here are two main ones for any junior:

  1. Never write numeric constants except 0, 1, and -1 in your code.
  2. Do not be so hard on yourself. All your wise seniors have similar stories, and some of them have many.

All Articles