perliedman / ocad2geojson

JavaScript OCAD file reader and exporter for GeoJSON, SVG and Mapbox Style Spec
https://www.liedman.net/ocad2geojson/
GNU Affero General Public License v3.0
39 stars 4 forks source link

Valid element types? #14

Open mpickering opened 4 years ago

mpickering commented 4 years ago

I am observing a SymbolElement where the type is reported to be 165. My understanding is that the type should only be between 1-4 but I am wondering whether this is a problem with the ocad file parsing logic or a problem in my OCAD file. The object in question seems to have quite a few coordinates but the lineWidth field also looks suspicious.

I am also seeing SymbolElement where the type is reported to be 0.

It's coming from an OCAD 11 file.

SymbolElement {
  buffer: <Buffer ad 0c 00 00 0b 00 06 00 9c 27 00 00 80 4c 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 b0 00 00 00 30 00 00 00 80 00 00 00 b9 bf 17 00 43 3a ... 1594922 more bytes>,
  offset: 471782,
  _startOffset: 346838,
  type: 165,
  flags: 9472,
  color: 2,
  lineWidth: -25342,
  diameter: 165,
  numberCoords: 15616,
  coords: [
    TdPoly(2) [ 655360, 7274752, xFlags: 166, yFlags: 2 ],
    TdPoly(2) [ -851968, -7732736, xFlags: 166, yFlags: 1 ],
    TdPoly(2) [ -2031616, -5439488, xFlags: 166, yFlags: 1 ],
    TdPoly(2) [ -4259840, -2686720, xFlags: 166, yFlags: 1 ],
    TdPoly(2) [ 7995392, -2424320, xFlags: 166, yFlags: 1 ],
    TdPoly(2) [ 5046272, 131072, xFlags: 166, yFlags: 1 ],
    TdPoly(2) [ 196608, 524544, xFlags: 167, yFlags: 1 ],
    TdPoly(2) [ -851968, 655872, xFlags: 167, yFlags: 0 ],
    TdPoly(2) [ -1638400, 1507328, xFlags: 167, yFlags: 0 ],
    TdPoly(2) [ -2228224, 4194560, xFlags: 167, yFlags: 0 ],
    TdPoly(2) [ -4390912, 6160896, xFlags: 167, yFlags: 0 ],
    TdPoly(2) [ -5111808, -7274496, xFlags: 167, yFlags: 0 ],
    TdPoly(2) [ -5767168, -4456192, xFlags: 167, yFlags: 0 ],
perliedman commented 4 years ago

Hm, yes this definitely looks like the symbol record has been read from the wrong offset, for some reason. As you say, the lineWidth is strange, and also there is no system in the coordinates, also the coordinates flags look weird.

Can't say that I have found anything like this before, at some point I have encountered symbols with negative number of coordinates (https://github.com/perliedman/ocad2geojson/blob/981a1bb9927c86b58eedee5909914f07c61ab852/src/ocad-reader/symbol-element.js#L24), but the other properties looked more or less sane in that case, IIRC. Still, the fact that you found another case of incorrect symbol element might indicate there is something wrong with how they are read from the file. One idea could be to add some error handling and see if ignoring this error makes the map render incorrectly.

In a few places we currently have code like this: https://github.com/perliedman/ocad2geojson/blob/65898cf00ad788f3f714018a467fe35bfabc6cba/src/ocad-reader/point-symbol.js#L22 - IIRC, I never managed to match that offset with the OCAD file format specification, but without it everything breaks.