@@ -21,8 +21,8 @@ export class Log {
21
21
this . loglevel = level ;
22
22
}
23
23
24
- show ( msg : any , level : number ) {
25
- if ( level <= this . loglevel ) console . log ( msg ) ;
24
+ show ( msg : string , level : number ) {
25
+ if ( level <= this . loglevel ) console . log ( msg . replace ( / \n | \r / g , "" ) ) ;
26
26
}
27
27
}
28
28
@@ -103,6 +103,10 @@ export class Tileserver {
103
103
* @return a tile for subsequent use or null if no valid Tile could be extracted.
104
104
*/
105
105
extractTile ( path : string ) : Tile | null {
106
+ if ( path . length > 1000 ) {
107
+ this . log . show ( `extractTile(): input path length exceeds limit` , LogLevels . ERROR ) ;
108
+ return null ;
109
+ }
106
110
const tile : Tile = { x : 0 , y : 0 , z : 0 } ;
107
111
const tilepath : RegExpMatchArray | null = path . match ( / \d + \/ \d + \/ \d + (? = \. m v t \b ) / g) ;
108
112
if ( tilepath ) {
@@ -121,6 +125,10 @@ export class Tileserver {
121
125
* @return the name of the source if found
122
126
*/
123
127
extractSource ( path : string ) : string | null {
128
+ if ( path . length > 1000 ) {
129
+ this . log . show ( `extractSource(): input path length exceeds limit` , LogLevels . ERROR ) ;
130
+ return null ;
131
+ }
124
132
// match the last word between slashes before the actual tile (3-numbers + extension)
125
133
const sourceCandidates : RegExpMatchArray | null = path . match ( / (? ! \/ ) \w + (? = \/ \d + \/ \d + \/ \d + \. m v t \b ) / g)
126
134
if ( sourceCandidates != null && sourceCandidates . length > 0 ) {
@@ -352,7 +360,7 @@ export class Tileserver {
352
360
const error : Error = _e as Error ;
353
361
mvt . res = - 4 ;
354
362
mvt . status = `[ERROR] - Database error: ${ error . message } ` ;
355
- this . log . show ( error , LogLevels . ERROR ) ;
363
+ this . log . show ( error . message , LogLevels . ERROR ) ;
356
364
return mvt ;
357
365
}
358
366
}
@@ -365,7 +373,7 @@ export class Tileserver {
365
373
data = Buffer . from ( "" ) ;
366
374
}
367
375
368
- this . log . show ( data , LogLevels . TRACE ) ;
376
+ this . log . show ( data . toString ( "base64" ) , LogLevels . TRACE ) ;
369
377
370
378
const uncompressedBytes = data . byteLength ;
371
379
if ( this . gzip ) mvt . data = await asyncgzip ( data ) as Buffer ;
0 commit comments