View Issue Details

IDProjectCategoryView StatusLast Update
0022177FPCDatabasepublic2014-09-24 09:28
ReporterGökhan Engin Assigned ToLudo Brands  
PrioritynormalSeveritycrashReproducibilityalways
Status closedResolutionfixed 
PlatformHandle TermOSWince 
Product Version2.4.4 
Target Version3.0.0Fixed in Version3.0.0 
Summary0022177: Bus error or misaligned data access.
DescriptionLike me are getting this error when working with DBF files, a very simple solution.

respects

have a nice days.

Error :

****************************************************************************

Bus error or misaligned data access. Press OK to ignore data and risk data corruption. Press
Cancel to kill the program.

****************************************************************************

Solution :

Check the length of the field name in DBF files. (Max. Field length = 10 chars).
Note : usually exceeds the maximum value of the length of the field name automatically when creating DBF file.

ps: sample file sended.
Tagsarm wince rtl, dbf
Fixed in Revision24157
FPCOldBugId
FPCTarget
Attached Files

Relationships

has duplicate 0022178 closedJoost van der Sluis Bus error or misaligned data access. 
related to 0017871 resolvedLacaK [WinCE] Bus error when using TSdfDataset 

Activities

2012-06-02 18:07

 

sample.rar (1,254,667 bytes)

Reinier Olislagers

2012-06-03 19:26

developer   ~0060234

The sample file compiles and runs without problems on Windows x86 (FPC 2.6.1, Lazarus 1.1 from 23 May 2012).
How does this demonstrate the problem? Is it meant to work? Or does it work on Windows desktop but fail on WinCE?

Also note these field length limitations (from bug http://bugs.freepascal.org/view.php?id=20134):
3: DBase III: 10 characters
4: DBase IV: 10 characters
7: DBase VII: 32 characters
8: FoxPro: 10 characters

Updated the wiki:
http://wiki.lazarus.freepascal.org/Lazarus_Tdbf_Tutorial#TableLevel_and_field_lengths

Ludo Brands

2012-06-03 20:51

developer   ~0060238

Last edited: 2012-06-03 20:53

I confirm the problem on wince. The ARM CPU does have data alignment requirements while x86 doesn't care, other than being slower for unaligned data access.
The problem occurs on dbf_idxfile.pas line 1554. Tag (a pointer) is cast to PMdx4Tag which is pointer to a record with an integer as first member. If tag is not on an integer boundary a bus error is inevitable. So this has not directly related to field names.
When the code is not designed with alignment in mind, it is very difficult to foresee the effort needed to repair alignment issues. In this case, the error happens in procedure ReadIndexes which means that the file format is not even aligned. So padding is not an option. Every pointer cast in the code has to be reviewed.

Marco van de Voort

2012-06-04 09:55

manager   ~0060245

http://www.freepascal.org/docs-html/ref/refse68.html

Ludo Brands

2012-06-04 10:35

developer   ~0060248

Of course. I hope you are not suggesting using UnAssigned for every pointer access. Every non-packed record created internally (stack or getmem) will be correctly aligned. Using Unassigned for accessing all these data would be a waste. I only found one packed record that is not aligned correctly: rStdPropEntry, word members DataOffset and DataSize are on odd addresses and used in dbf_dbffile line 971. These are easily solved. The main problem comes from data that are defined as a sequence of byte/chars and are cast to something else that needs to be aligned. Reason why every pointer cast in the code has to be reviewed. That is, if somebody wants to fix code that is "deprecated 'Abandoned by maintainer, no longer supported by FPC team.'"

Marco van de Voort

2012-06-04 11:58

manager   ~0060253

If there is a fix, why not. The warning is just there to make sure that users don't expect bugs to be fixed quickly till a new maintainer pops up.

With the unaligned remark, I assumed that the problematic code was accessing records or values > 1 byte in some incoming buffer with streamed data (which is afaik the main use of unaligned).

Of course reworking with a Move to an aligned record/value is possible too, but then performance suffers on other systems.

But most importantly, it allows to test if that is the main problem, or just the first of a long sequence.

Ludo Brands

2013-04-05 11:55

developer   ~0066817

Fixed some unaligned memory accesses in dbf_idxfile.pas in rev 24155. The test program runs fine now on ARM (tested on debian with sigbus signaling and warning on)
Please retest and close the issue when fixed. Possibly there are other unaligned accesses that are not fixed but the attached test and the latest dbtestframework test suite for TDBF pass without any ARM related errors.

Ludo Brands

2013-04-05 12:48

developer   ~0066818

fixed some other unaligned accesses in dbf_dbffile.pas in revision 24157.

Reinier Olislagers

2014-09-24 09:28

developer   ~0077581

Seems unlikely reporter is going to close the issue due to bug age.

Issue History

Date Modified Username Field Change
2012-06-02 18:07 Gökhan Engin New Issue
2012-06-02 18:07 Gökhan Engin Status new => assigned
2012-06-02 18:07 Gökhan Engin Assigned To => Joost van der Sluis
2012-06-02 18:07 Gökhan Engin File Added: sample.rar
2012-06-02 22:06 Jonas Maebe Relationship added has duplicate 0022178
2012-06-03 13:44 Gökhan Engin Tag Attached: arm wince rtl
2012-06-03 19:26 Reinier Olislagers Note Added: 0060234
2012-06-03 20:51 Ludo Brands Note Added: 0060238
2012-06-03 20:53 Ludo Brands Note Edited: 0060238
2012-06-04 09:55 Marco van de Voort Note Added: 0060245
2012-06-04 10:35 Ludo Brands Note Added: 0060248
2012-06-04 11:58 Marco van de Voort Note Added: 0060253
2012-06-09 15:28 Marco van de Voort Relationship added related to 0017871
2013-03-30 13:20 Reinier Olislagers Tag Attached: dbf
2013-04-03 15:29 Reinier Olislagers Assigned To Joost van der Sluis => Ludo Brands
2013-04-05 11:55 Ludo Brands Note Added: 0066817
2013-04-05 11:56 Ludo Brands Fixed in Revision => 24155
2013-04-05 11:56 Ludo Brands Status assigned => resolved
2013-04-05 11:56 Ludo Brands Fixed in Version => 2.7.1
2013-04-05 11:56 Ludo Brands Resolution open => fixed
2013-04-05 11:56 Ludo Brands Target Version => 2.8.0
2013-04-05 12:47 Ludo Brands Status resolved => feedback
2013-04-05 12:47 Ludo Brands Resolution fixed => reopened
2013-04-05 12:48 Ludo Brands Fixed in Revision 24155 => 24157
2013-04-05 12:48 Ludo Brands Note Added: 0066818
2013-04-05 12:48 Ludo Brands Status feedback => resolved
2013-04-05 12:48 Ludo Brands Resolution reopened => fixed
2014-09-24 09:28 Reinier Olislagers Note Added: 0077581
2014-09-24 09:28 Reinier Olislagers Status resolved => closed