@@ -502,16 +502,30 @@ Promise.all([plugins.dbConnection(countlyConfig), plugins.dbConnection("countly_
502502 res . sendFile ( __dirname + '/public/images/default_app_icon.png' ) ;
503503 }
504504 else {
505- countlyFs . getStats ( "appimages" , __dirname + '/public/appimages/' + req . params [ 0 ] , { id : req . params [ 0 ] } , function ( err , stats ) {
505+ var appImagePath = common . resolvePathInBase ( __dirname + '/public/appimages' , req . params [ 0 ] ) ;
506+ if ( ! appImagePath ) {
507+ res . sendFile ( __dirname + '/public/images/default_app_icon.png' ) ;
508+ return ;
509+ }
510+ countlyFs . getStats ( "appimages" , appImagePath , { id : req . params [ 0 ] } , function ( err , stats ) {
506511 if ( err || ! stats || ! stats . size ) {
507512 res . sendFile ( __dirname + '/public/images/default_app_icon.png' ) ;
508513 }
509514 else {
510- countlyFs . getStream ( "appimages" , __dirname + '/public/appimages/' + req . params [ 0 ] , { id : req . params [ 0 ] } , function ( err2 , stream ) {
515+ countlyFs . getStream ( "appimages" , appImagePath , { id : req . params [ 0 ] } , function ( err2 , stream ) {
511516 if ( err2 || ! stream ) {
512517 res . sendFile ( __dirname + '/public/images/default_app_icon.png' ) ;
513518 }
514519 else {
520+ stream . on ( 'error' , function ( streamErr ) {
521+ log . e ( streamErr ) ;
522+ if ( ! res . headersSent ) {
523+ res . sendFile ( __dirname + '/public/images/default_app_icon.png' ) ;
524+ }
525+ else {
526+ res . end ( ) ;
527+ }
528+ } ) ;
515529 res . writeHead ( 200 , {
516530 'Accept-Ranges' : 'bytes' ,
517531 'Cache-Control' : 'public, max-age=31536000' ,
@@ -536,16 +550,30 @@ Promise.all([plugins.dbConnection(countlyConfig), plugins.dbConnection("countly_
536550 res . sendFile ( __dirname + '/public/images/default_member_icon.png' ) ;
537551 }
538552 else {
539- countlyFs . getStats ( "memberimages" , __dirname + '/public/' + req . path , { id : req . params [ 0 ] } , function ( err , stats ) {
553+ var memberImagePath = common . resolvePathInBase ( __dirname + '/public/memberimages' , req . params [ 0 ] ) ;
554+ if ( ! memberImagePath ) {
555+ res . sendFile ( __dirname + '/public/images/default_member_icon.png' ) ;
556+ return ;
557+ }
558+ countlyFs . getStats ( "memberimages" , memberImagePath , { id : req . params [ 0 ] } , function ( err , stats ) {
540559 if ( err || ! stats || ! stats . size ) {
541560 res . sendFile ( __dirname + '/public/images/default_member_icon.png' ) ;
542561 }
543562 else {
544- countlyFs . getStream ( "memberimages" , __dirname + '/public/' + req . path , { id : req . params [ 0 ] } , function ( err2 , stream ) {
563+ countlyFs . getStream ( "memberimages" , memberImagePath , { id : req . params [ 0 ] } , function ( err2 , stream ) {
545564 if ( err2 || ! stream ) {
546565 res . sendFile ( __dirname + '/public/images/default_member_icon.png' ) ;
547566 }
548567 else {
568+ stream . on ( 'error' , function ( streamErr ) {
569+ log . e ( streamErr ) ;
570+ if ( ! res . headersSent ) {
571+ res . sendFile ( __dirname + '/public/images/default_member_icon.png' ) ;
572+ }
573+ else {
574+ res . end ( ) ;
575+ }
576+ } ) ;
549577 res . writeHead ( 200 , {
550578 'Accept-Ranges' : 'bytes' ,
551579 'Cache-Control' : 'public, max-age=31536000' ,
@@ -564,15 +592,26 @@ Promise.all([plugins.dbConnection(countlyConfig), plugins.dbConnection("countly_
564592 } ) ;
565593
566594 app . get ( countlyConfig . path + "*/screenshots/*" , function ( req , res ) {
567- countlyFs . getStats ( "screenshots" , __dirname + '/public/' + req . path , { id : "core" } , function ( err , stats ) {
595+ var screenshotPath = common . resolvePathInBase ( __dirname + '/public' , req . path ) ;
596+ if ( ! screenshotPath ) {
597+ return res . send ( false ) ;
598+ }
599+ countlyFs . getStats ( "screenshots" , screenshotPath , { id : "core" } , function ( err , stats ) {
568600 if ( err || ! stats || ! stats . size ) {
569601 return res . send ( false ) ;
570602 }
571603
572- countlyFs . getStream ( "screenshots" , __dirname + '/public/' + req . path , { id : "core" } , function ( err2 , stream ) {
604+ countlyFs . getStream ( "screenshots" , screenshotPath , { id : "core" } , function ( err2 , stream ) {
573605 if ( err2 || ! stream ) {
574606 return res . send ( false ) ;
575607 }
608+ stream . on ( 'error' , function ( streamErr ) {
609+ log . e ( streamErr ) ;
610+ if ( ! res . headersSent ) {
611+ return res . send ( false ) ;
612+ }
613+ res . end ( ) ;
614+ } ) ;
576615
577616 res . writeHead ( 200 , {
578617 'Accept-Ranges' : 'bytes' ,
0 commit comments