[Gambas-bugtracker] Bug #1629: segmentation fault with gb.uncompress

bugtracker at gambaswiki.org bugtracker at gambaswiki.org
Mon Jul 29 14:09:29 CEST 2019


http://gambaswiki.org/bugtracker/edit?object=BUG.1629&from=L21haW4-

Comment #4 by Gen BRAGA:

There are two issues indeed.

One about Byte[].ToString(), which can be worked around by passing the array size as parameter in the ToString method. Doing so makes the destination string get the correct size besides the intermediate null bytes. But i think it should not stop at the first null byte, when not passing anything as parameters.

The second issue, about String() method from gb.uncompress class. This one I couldnt track down, since sometimes it returns "invalid compressed string" or simply raise a segmentation fault, depends upon the size of the compressed string...

I think i didnt make it clear enough, so here goes the sample code anyway. 

------------------------------

' Gambas class file

'Using the line below, it works but still got a shorter string when calling byte[].toString() at line "sTemp2 = aCompressed.ToString()" because the null bytes
Public sInitial As String = "The quick brown fox jumps over the lazy dog, The quick brown fox jumps over the lazy dog, The quick brown fox jumps over the lazy dog"
'Using the line below, got segfault both ways
'Public sInitial As String = "The quick brown fox jumps over the lazy dog, The quick brown fox jumps over the lazy dog, The quick brown fox jumps over the lazy dog,The quick brown fox jumps over the lazy dog, The quick brown fox jumps over the lazy dog, The quick brown fox jumps over the lazy dog,"
Public sCompressed As String
Public sTemp1 As String
Public sTemp2 As String
Public aCompressed As New Byte[]

Public zip As New Compress
Public unzip As New UnCompress

Public Sub Form_Open()

  zip.Type = "bzlib2"
  unzip.Type = "bzlib2"

  'string to compressed string, then to byte array.
  sCompressed = zip.String(sInitial, zip.max, False)
  aCompressed = Byte[].FromString(sCompressed)

  sTemp1 = aCompressed.ToString(0, aCompressed.Length)     ' this one works ok
  sTemp2 = aCompressed.ToString()                          ' will be a shorter string than it should be

  Print unzip.String(sTemp1)
  Print unzip.String(sTemp2)

End

Gen BRAGA changed the state of the bug to: Accepted.




More information about the Bugtracker mailing list