rtaylor187 / CanonTxtCvt

Convert Canon StarWriter JET 300 text files to RTF
2 stars 0 forks source link

Source array was not long enough #1

Open pingnu opened 1 year ago

pingnu commented 1 year ago

System.ArgumentException: 'Source array was not long enough. Check srcIndex and length, and the array's lower bounds.'

        byte[] docText = new byte[txtLen];
        Array.Copy(fileBytes, 0x108, docText, 0, txtLen - 0x88); 

        // start w/default style
        styleSet.Clear();
        styleSet.Add(0, new StyleInf
pingnu commented 1 year ago

Coop3.TXT

rtaylor187 commented 1 year ago

Well... that looks like a bug - or seriously unexpected content.

I'm overseas at the moment, but in a couple weeks - when I'm back at home with that source code and can figure out what I wrote 3 years ago 😮 - I'll get it fixed.

Do you have any other example files with the same issue (i.e. beyond Coop3.TXT)?

-= Rich

pingnu commented 1 year ago

I was delighted to find your program It fails on about 60%.  They were written by my late father and mostly ancestry data so very helpfull to me. The rest are shares and finance which I have no interest in. I built it with Visual Studio 2022 I can send you all the failed files. Sent from 07881660777 -------- Original message --------From: Rich Taylor @.> Date: 01/05/2023 1:02 pm (GMT+00:00) To: rtaylor187/CanonTxtCvt @.> Cc: Carl Parsons @.>, Author @.> Subject: Re: [rtaylor187/CanonTxtCvt] Source array was not long enough (Issue

1)

Well... that looks like a bug - or seriously unexpected content. I'm overseas at the moment, but in a couple weeks - when I'm back at home with that source code and can figure out what I wrote 3 years ago 😮 - I'll get it fixed. Do you have any other example files with the same issue (i.e. beyond Coop3.TXT)? -= Rich

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>

rtaylor187 commented 1 year ago

Carl,

I grabbed a few files from home and code from GitHub. I identified one basic issue - I was getting 4 bytes for the data length. For your Coop3.txt file the data length is 2 bytes long - then next 2 bytes have unknown (but not 0) data, so that made for a buffer overflow.

While a simple change (4 -> 2 byte data length) does avoid failing when reading your file... there may be other issues. The data in your file doesn't line up vertically - so there may be other improvements needed. Also, blindly changing this means that a file's data cannot be longer than 64K - that might be legit.

Before I commit that change I want to run through all the files I have and ensure the change doesn't break anything. I can do that in a week or so when I'm back at home. I can also try your file on the actual machine to see if there are some other settings going on.

In the meantime, source change you can try is: convert.cs, line 215, change "ToInt32" to "ToInt16". That'll get a 2-byte length for text data. Let me know if that fixes everything (or...)

-= Rich

pingnu commented 1 year ago

We are off till Wednesday Edinbough my wifes birthday. I have two stacks of Brother printer disks to convert so might play with your program to see if I can do it. Disks are not DOS so have a catweazle disk reader to read themSent from 07881660777 -------- Original message --------From: Rich Taylor @.> Date: 06/05/2023 8:29 pm (GMT+00:00) To: rtaylor187/CanonTxtCvt @.> Cc: Carl Parsons @.>, Author @.> Subject: Re: [rtaylor187/CanonTxtCvt] Source array was not long enough (Issue

1)

Carl, I grabbed a few files from home and code from GitHub. I identified one basic issue - I was getting 4 bytes for the data length. For your Coop3.txt file the data length is 2 bytes long - then next 2 bytes have unknown (but not 0) data, so that made for a buffer overflow. While a simple change (4 -> 2 byte data length) does avoid failing when reading your file... there may be other issues. The data in your file doesn't line up vertically - so there may be other improvements needed. Also, blindly changing this means that a file's data cannot be longer than 64K - that might be legit. Before I commit that change I want to run through all the files I have and ensure the change doesn't break anything. I can do that in a week or so when I'm back at home. I can also try your file on the actual machine to see if there are some other settings going on. In the meantime, source change you can try is: convert.cs, line 215, change "ToInt32" to "ToInt16". That'll get a 2-byte length for text data. Let me know if that fixes everything (or...) -= Rich

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>

rtaylor187 commented 1 year ago

Carl,

I finally have some time to work on this.

I tested the change I mentioned above (convert.cs file) and it appears to work on all the files I have. I will get it checked in soon.

Did you get all of your files converted? Are there any more problems you had - if so, pls. send me files via here or we can connect directly somehow.

-= Rich Taylor

pingnu commented 1 year ago

no sorry got distracted I will check it out within a week hopefully. working on piwars robot at a friends at moment.Sent from 07881660777 -------- Original message --------From: Rich Taylor @.> Date: 25/09/2023 10:25 pm (GMT+00:00) To: rtaylor187/CanonTxtCvt @.> Cc: Carl Parsons @.>, Author @.> Subject: Re: [rtaylor187/CanonTxtCvt] Source array was not long enough (Issue

1)

Carl, I finally have some time to work on this. I tested the change I mentioned above (convert.cs file) and it appears to work on all the files I have. I will get it checked in soon. Did you get all of your files converted? Are there any more problems you had - if so, pls. send me files via here or we can connect directly somehow. -= Rich Taylor

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>

pingnu commented 1 year ago

On 2023-09-25 22:25, Rich Taylor wrote:

Carl,

I finally have some time to work on this.

I tested the change I mentioned above (convert.cs file) and it appears to work on all the files I have. I will get it checked in soon.

NO I only sent some of the files so I have loads of disks todo They are either my late dads share dealing which I have no interest but also his Ancestry work which I would like as much as I can I now own a greaseweazle V4 perhaps read friends brother, apple 2 and Cananon typwriter disks

Will be interested in the changes I am no C# expert but I do some and will study your changes and do some more testing for you

Carl

Did you get all of your files converted? Are there any more problems you had - if so, pls. send me files via here or we can connect directly somehow.

-= Rich Taylor

-- Reply to this email directly, view it on GitHub [1], or unsubscribe [2]. You are receiving this because you authored the thread.Message ID: @.***>

Links:

[1] https://github.com/rtaylor187/CanonTxtCvt/issues/1#issuecomment-1734484433 [2] https://github.com/notifications/unsubscribe-auth/ACUQEFXQ5M6E7KTERWG3CGTX4HZEDANCNFSM6AAAAAAXRDGD5Q

-- Carl Parsons carl @.*** Home: 01480 831607 Mobile: 07881660777