Recent

Author Topic: [SOLVED]base64 string encoding bug?  (Read 4489 times)

sib_konst

  • Newbie
  • Posts: 3
[SOLVED]base64 string encoding bug?
« on: September 07, 2012, 05:27:34 am »
Hello, i'm trying to encode random, user defined string with base64 and write it to a file. When string includes digital sequence of two digits like:
Code: [Select]
first_digit=Inc(second_digit) //(for example: '98' or '54')I'm getting 'External: SIGSEGV' error. Is that kind of bug, or i'm doing something wrong? If it's a bug, what else sequences i need to filter?
Attaching program source.
« Last Edit: September 07, 2012, 09:56:29 am by sib_konst »

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: base64 string encoding bug?
« Reply #1 on: September 07, 2012, 08:53:35 am »
Free encoder before freeing encoded. Encoder is created with encoded as param and when freeing encoder it apparently refers to encoded which is already freed in your case.

sib_konst

  • Newbie
  • Posts: 3
Re: base64 string encoding bug?
« Reply #2 on: September 07, 2012, 09:24:55 am »
Works fine now, thanks.
And to 'expand horizonts': why that error appeared only in case of the above digital sequence?
« Last Edit: September 07, 2012, 09:34:51 am by sib_konst »

KpjComp

  • Hero Member
  • *****
  • Posts: 680
Re: base64 string encoding bug?
« Reply #3 on: September 07, 2012, 09:47:23 am »
Quote
why that error appeared only in case of the above digital sequence

Welcome the wonderful world of lost pointers. :)

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: base64 string encoding bug?
« Reply #4 on: September 07, 2012, 09:58:15 am »
I also have a crash with "abcde". From a quick look at the code, Destroy calls Flush which is writing out the last bytes. base64 encoding is always a multiple of 4 bytes (3 bytes are transformed to 4 bytes). I don't know exactly what the purpose of your code is but you are not base64 encoding the password. You are only storing the first length(password) characters of the base64 encoding. If you want the "real" base64 encoding of the password you could simply use
Code: [Select]
output:=EncodeStringBase64(edtPasswd.Text);instead of using the streams. If you want to use streams, take a look at the implementation of EncodeStringBase64 for the correct way of ding this.

sib_konst

  • Newbie
  • Posts: 3
Re: base64 string encoding bug?
« Reply #5 on: September 07, 2012, 10:20:44 am »
you could simply use
Code: [Select]
output:=EncodeStringBase64(edtPasswd.Text);instead of using the streams. If you want to use streams, take a look at the implementation of EncodeStringBase64 for the correct way of ding this.
So it's something like i've tried to ride from Vienna to Frankfurt, but through Rome. And arrived to Krakow, as a result...
Thanks for showing me the right way  :)

 

TinyPortal © 2005-2018