Bug 134516 - Invalid string handling with random files
Summary: Invalid string handling with random files
Status: RESOLVED NOTABUG
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
6.4.4.2 release
Hardware: x86-64 (AMD64) Windows (All)
: medium minor
Assignee: Not Assigned
URL:
Whiteboard:
Keywords: needsUXEval
Depends on:
Blocks:
 
Reported: 2020-07-05 06:59 UTC by jc bourg
Modified: 2020-07-28 08:52 UTC (History)
4 users (show)

See Also:
Crash report or crash signature:


Attachments
document with macro (7.78 KB, application/vnd.oasis.opendocument.text)
2020-07-17 18:43 UTC, Terrence Enger
Details
document with macro (9.52 KB, application/vnd.oasis.opendocument.text)
2020-07-17 21:13 UTC, Terrence Enger
Details
Sample VB code (336 bytes, text/plain)
2020-07-25 08:48 UTC, jc bourg
Details
sample output file (17 bytes, application/octet-stream)
2020-07-25 08:49 UTC, jc bourg
Details

Note You need to log in before you can comment on or make changes to this bug.
Description jc bourg 2020-07-05 06:59:31 UTC
When using the PUT statement with a string on a random access file,
then the 2  length bytes ar written and the string gets truncated the last 2 characters.
Comment 1 Terrence Enger 2020-07-17 18:43:50 UTC
Created attachment 163201 [details]
document with macro

jc_bourg, are you using LO Basic, a random file and the "put"
operation?

OpenOffice.org Macros Explained (OOME_3_0.pdf,
<http://www.pitonyak.org/OOME_3_0.pdf>), section 8.8 "Reading and
writing data" says of random files and operation "put":

    If the data variable is a Variant, an integer identifying the data
    type precedes the data.

and

    When Put places a string as a Variant, it actually writes the
    VarType, the string length, and then the string.

My experiment in a local build of commit e54ff4c1 on debian-buster
gives results like Andrew Pitonyak described.  Neither a String nor a
Variant shows truncation of the last two characters.  Macro "one" in
the attached demo01.odt is the experiment.


I am setting status NEEDINFO.  jc_bourg, please set bug status back to
UNCONFIRMED when you reply.
Comment 2 Terrence Enger 2020-07-17 21:13:18 UTC
Created attachment 163209 [details]
document with macro

Trying again ... after I saved the file.
Comment 3 jc bourg 2020-07-25 08:48:28 UTC
Created attachment 163504 [details]
Sample VB code

Please find attached a sample basic code
Comment 4 jc bourg 2020-07-25 08:49:28 UTC
Created attachment 163505 [details]
sample output file

hex dump:
file name: Test.DAT
mime type: 

0000-0010:  05 00 54 65-73 05 00 54-65 73 05 00-54 65 73 74  ..Tes..T es..Test
0000-0011:  33                                               3
Comment 5 jc bourg 2020-07-25 08:52:34 UTC
i did upload a sample basic code, out file and hex dump
that produces the error.

Note:
Setting the record length to 7, will no longer truncate the text strings.
But having the 2 byte length in each record, does not make any sense, in a fixed length random access file.
Comment 6 QA Administrators 2020-07-26 03:52:36 UTC Comment hidden (obsolete)
Comment 7 Terrence Enger 2020-07-26 13:11:54 UTC
I suspect that the the two-byte length has been a feature of LO 
for a long time (the book I cited is from 2016, and it was already
version 3) and that there are macros which rely on this feature.  
Thus I think we should keep the present behavior.  To invite further
comments, I am adding keyword needsUXEval.

Meanwhile, the language provides other open modes and other output
operators which may better suit your needs.
Comment 8 Heiko Tietze 2020-07-27 13:01:24 UTC
What do you think, Alain & Andrew?
Comment 9 Alain Romedenne 2020-07-27 15:37:00 UTC
Not a bug:

-  If the variable being written is a variable-length string, Put writes a 2-byte descriptor containing the string length and then the variable. The record length specified by the Len clause in the Open statement must be at least 2 bytes greater than the actual length of the string.

   as per https://docs.microsoft.com/fr-fr/office/vba/language/reference/user-interface-help/put-statement

- The Put statement behaves differently, depending on the type of file you're using. 
Random files: The first two bytes written indicate the length of the string. Then the Put statement writes the number of characters specified by that length. If variableName is not initialized, the Put statement writes a string of length 0.

  as per https://help.hcltechsw.com/dom_designer/9.0.1/appdev/LSAZ_PUT_STATEMENT.html