libredwg icon indicating copy to clipboard operation
libredwg copied to clipboard

r2013 section-map overflows

Open epakshay opened this issue 6 years ago • 9 comments

I am using command line tool like : dwg2dxf data.dwg

I tried converting few dwg file few worked properly. But when i tried to convert a file which have multiple feautre i.e point, line and polygon, it gives an error like this:

Reading DWG file data.dwg
Section[10132]=9933, size:  4864, address: 0xfff38ca
Section[10133]=9934, size:  4256, address: 0xfff4bca
Section[10134]=9935, size:  4672, address: 0xfff5c6a

=== Data Section (Section Info 11395) ===
ERROR: bit_read_RC buffer overflow at 267997258
ERROR: bit_read_RC buffer overflow at 267997258
ERROR: bit_read_RC buffer overflow at 267997258
ERROR: bit_read_RC buffer overflow at 267997258
ERROR: Invalid Data Section Page Map type 0x0 != 0x4163003b
ERROR: Failed to decode file: data.dwg 0x100

The file was created to plot few GIS i.e location related points and the size was upto 170MB. Please help me out in this. Thanks.

epakshay avatar Sep 18 '19 13:09 epakshay

Which DWG version exactly? can you post the header and the failing section part of the log, best with dwg2dxf - v3, thanks. Best would be the zipped dwg, sent to my email. It could be something like GH #93

rurban avatar Sep 18 '19 14:09 rurban

Hi Reini, I tried with dwg2dxf - v3, but the command does not respond. Not able to attach the zipped file here due to size limitation. Here is the attached file link of google drive.

https://drive.google.com/open?id=1INk71FysZ69HjLP4k3XypjO3eopxDAqq

Thanks

epakshay avatar Sep 23 '19 01:09 epakshay

Looks like an address overflow to me. 0xfff5c6a is almost at the end of 32bit (RL) types. $ printf %x 267997258 ff9504a Might need to extend a few types (Dwg_Section.address) from RL to uint64_t or RLL.

But more importantly address 0xff9504a > dwgsize: 0xac38442 (180585538) libdxfrw fails with the same problem.

Suspicious sizes, probably causing the overflow: perl -anle 'if (/address/ && $F[2] > 29856) { print $_}' data_gh144.log

Section[4129]=528673, size: 7643136, address: 0x55255c3
Section[4364]=529673, size: 7643136, address: 0x6090a8c
Section[4612]=530176, size: 7643136, address: 0x6c40667
Section[4614]=530433, size: 7643136, address: 0x738f387
Section[4696]=4690, size: 29888, address: 0x7c4d227
Section[4702]=4696, size: 29920, address: 0x7c6aac7
Section[4870]=4615, size: 545856, address: 0x7f6f487
Section[4871]=7602176, size: 546048, address: 0x7ff48c7
Section[4897]=6433, size: 7643145, address: 0x80ea534
Section[5385]=5375, size: 542784, address: 0x90ccfd2
Section[5386]=7643136, size: 542976, address: 0x9151812
Section[5392]=532741, size: 7643136, address: 0x91ed05e
Section[5644]=5375, size: 546284, address: 0x9dbd32a
Section[5645]=7643136, size: 546304, address: 0x9e42916
Section[5648]=533762, size: 7643136, address: 0x9ed15b6
Section[5663]=529936, size: 7643136, address: 0xa65bf86
Section[5903]=534272, size: 7643136, address: 0xb200d36
Section[5904]=534528, size: 7643232, address: 0xb94ad36
Section[5907]=534531, size: 7643136, address: 0xc09f776
Section[6153]=535030, size: 542720, address: 0xcc192aa
Section[10066]=-175, size: 98944, address: 0xff240aa
Section[10107]=11395, size: 99488, address: 0xff9504a
Section[10108]=-2871, size: 89440, address: 0xffad4ea

rurban avatar Sep 23 '19 06:09 rurban

I'm afraid you need to use the TeighaFileConverter for now. There's something wrong with the spec when reading so many sections which overflow the dwg size.

BTW, I found those problem only in r2013 DWGs, not with other versions.

rurban avatar Sep 23 '19 07:09 rurban

Ok. Thanks for the reply. How can i use TeighaFileConverter? Does it provide command line tool. I am searching for the same, but didn't find this conversion code. Can you please share its link so that i can look into its documentation too. Thanks

epakshay avatar Sep 23 '19 07:09 epakshay

The testcases in GH #132 (also r2013) do have the same problems.

rurban avatar Sep 23 '19 12:09 rurban

https://www.google.com/search?q=TeighaFileConverter finds enough. This tool exists for linux, mac, windows, and can also be used via cmdline. see e.g. dxf-roundtrip.sh

TeighaFileConverter "indir" "outdir" ACAD$VER DWF|DWG 0 1 infile(s)

rurban avatar Sep 23 '19 12:09 rurban

I got now a good testcase where libdxfrw works, and libredwg fails with section gaps. Thanks @timoria21 for the CFI dwg.

Found and fixed one fatal error with 'CFI - RIC - Room v3-2.dwg'

rurban avatar Apr 08 '22 07:04 rurban

Thanks, happy to hear that these files helped you to fix some bugs.

timoria21 avatar Apr 11 '22 06:04 timoria21