Compare commits

...

6 Commits

Author SHA1 Message Date
252ca8542a Fixed LEB128 decoding + types 2025-01-06 22:42:29 +01:00
14069640b4
Fixed changelog URL 2025-01-06 20:59:59 +01:00
4e2dfabc9d Cosmetics 2025-01-06 20:47:11 +01:00
8e49440a02 Remove remaining protobuf stuff 2025-01-06 20:13:55 +01:00
badd834b59 Fixed float/double values parsing 2025-01-06 20:12:28 +01:00
0a4543ddcf Added missing type checks 2025-01-06 19:48:54 +01:00
3 changed files with 60 additions and 24 deletions

6
.gitignore vendored
View File

@ -1,10 +1,6 @@
# Object files
*.o
# Protobuf stuff
protobuf/vector_tile.pb.cc
protobuf/vector_tile.pb.h
# Qt stuff
/.qmake.stash
moc_*.cpp
@ -14,4 +10,4 @@ Makefile*
# lib
libpbf.so
pbf.dylib
libpbf.dylib

View File

@ -96,7 +96,7 @@ algorithm to work properly.
* Expressions are not supported in the styles, only property functions are implemented.
## Changelog
[Changelog](https://build.opensuse.org/package/view_file/home:tumic:QtPBFImagePlugin/QtPBFImagePlugin/libqt5-qtpbfimageformat.changes)
[Changelog](https://build.opensuse.org/projects/home:tumic:QtPBFImagePlugin/packages/QtPBFImagePlugin/files/qt6-qtpbfimageformat.changes)
## Status
A picture is worth a thousand words.

View File

@ -3,6 +3,11 @@
#define TYPE(tag) (tag & 0x07)
#define FIELD(tag) (tag >> 3)
#define VARINT 0
#define I64 1
#define LEN 2
#define I32 5
struct CTX
{
CTX(const QByteArray &ba)
@ -10,7 +15,7 @@ struct CTX
const char *bp;
const char *be;
quint64 tag;
quint32 tag;
};
static inline qint64 zigzag64decode(quint64 value)
@ -24,9 +29,8 @@ static bool varint(CTX &ctx, T &val)
{
val = 0;
uint shift = 0;
const char *end = qMin(ctx.be, ctx.bp + sizeof(val));
while (ctx.bp < end) {
while (ctx.bp < ctx.be) {
val |= ((quint8)*ctx.bp & 0x7F) << shift;
shift += 7;
if (!((quint8)*ctx.bp++ & 0x80))
@ -38,12 +42,15 @@ static bool varint(CTX &ctx, T &val)
static bool str(CTX &ctx, QByteArray &val)
{
quint64 len;
qint32 len;
if (TYPE(ctx.tag) != LEN)
return false;
if (!varint(ctx, len))
return false;
if (ctx.bp + len > ctx.be)
return false;
val = QByteArray::fromRawData(ctx.bp, len);
ctx.bp += len;
@ -52,20 +59,26 @@ static bool str(CTX &ctx, QByteArray &val)
static bool dbl(CTX &ctx, double &val)
{
if (TYPE(ctx.tag) != I64)
return false;
if (ctx.bp + sizeof(val) > ctx.be)
return false;
memcpy(&val, ctx.bp, sizeof(val));
ctx.bp += sizeof(val);
return true;
}
static bool flt(CTX &ctx, float &val)
{
if (TYPE(ctx.tag) != I32)
return false;
if (ctx.bp + sizeof(val) > ctx.be)
return false;
memcpy(&val, ctx.bp, sizeof(val));
ctx.bp += sizeof(val);
return true;
}
@ -74,8 +87,8 @@ static bool packed(CTX &ctx, QVector<quint32> &vals)
{
quint32 v;
if (TYPE(ctx.tag) == 2) {
quint64 len;
if (TYPE(ctx.tag) == LEN) {
qint32 len;
if (!varint(ctx, len))
return false;
const char *ee = ctx.bp + len;
@ -87,7 +100,7 @@ static bool packed(CTX &ctx, QVector<quint32> &vals)
vals.append(v);
}
return (ctx.bp == ee);
} else if (TYPE(ctx.tag) == 0) {
} else if (TYPE(ctx.tag) == VARINT) {
if (!varint(ctx, v))
return false;
vals.append(v);
@ -98,19 +111,19 @@ static bool packed(CTX &ctx, QVector<quint32> &vals)
static bool skip(CTX &ctx)
{
quint64 len = 0;
qint32 len = 0;
switch (TYPE(ctx.tag)) {
case 0:
case VARINT:
return varint(ctx, len);
case 1:
case I64:
len = 8;
break;
case 2:
case LEN:
if (!varint(ctx, len))
return false;
break;
case 5:
case I32:
len = 4;
break;
default:
@ -126,8 +139,12 @@ static bool skip(CTX &ctx)
static bool value(CTX &ctx, QVariant &val)
{
if (TYPE(ctx.tag) != LEN)
return false;
qint32 len;
QByteArray ba;
quint64 len, num;
quint64 num;
double dnum;
float fnum;
@ -159,21 +176,29 @@ static bool value(CTX &ctx, QVariant &val)
val = QVariant(dnum);
break;
case 4:
if (TYPE(ctx.tag) != VARINT)
return false;
if (!varint(ctx, num))
return false;
val = QVariant(static_cast<qint64>(num));
break;
case 5:
if (TYPE(ctx.tag) != VARINT)
return false;
if (!varint(ctx, num))
return false;
val = QVariant(num);
break;
case 6:
if (TYPE(ctx.tag) != VARINT)
return false;
if (!varint(ctx, num))
return false;
val = QVariant(zigzag64decode(num));
break;
case 7:
if (TYPE(ctx.tag) != VARINT)
return false;
if (!varint(ctx, num))
return false;
val = QVariant(num ? true : false);
@ -189,8 +214,12 @@ static bool value(CTX &ctx, QVariant &val)
static bool feature(CTX &ctx, Data::Feature &f)
{
quint64 len;
quint8 e;
quint32 e;
if (TYPE(ctx.tag) != LEN)
return false;
qint32 len;
if (!varint(ctx, len))
return false;
@ -204,6 +233,8 @@ static bool feature(CTX &ctx, Data::Feature &f)
switch (FIELD(ctx.tag)) {
case 1:
if (TYPE(ctx.tag) != VARINT)
return false;
if (!varint(ctx, f.id))
return false;
break;
@ -212,11 +243,13 @@ static bool feature(CTX &ctx, Data::Feature &f)
return false;
break;
case 3:
if (TYPE(ctx.tag) != VARINT)
return false;
if (!varint(ctx, e))
return false;
if (e > Data::GeomType::POLYGON)
return false;
f.type = (Data::GeomType)e;
f.type = static_cast<Data::GeomType>(e);
break;
case 4:
if (!packed(ctx, f.geometry))
@ -233,8 +266,11 @@ static bool feature(CTX &ctx, Data::Feature &f)
static bool layer(CTX &ctx, Data::Layer &l)
{
if (ctx.tag == 0x1a) {
quint64 len;
if (FIELD(ctx.tag) == 3) {
if (TYPE(ctx.tag) != LEN)
return false;
qint32 len;
if (!varint(ctx, len))
return false;
@ -267,10 +303,14 @@ static bool layer(CTX &ctx, Data::Layer &l)
return false;
break;
case 5:
if (TYPE(ctx.tag) != VARINT)
return false;
if (!varint(ctx, l.extent))
return false;
break;
case 15:
if (TYPE(ctx.tag) != VARINT)
return false;
if (!varint(ctx, l.version))
return false;
break;