]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - shared/extra-utils/ffprobe.ts
Don't inject untrusted input
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / ffprobe.ts
index b95202464f105c7af4236a17364ad894d0cdf901..7efc58a0d944950e5c8c6ae7287d4a62ceb0af7d 100644 (file)
@@ -1,5 +1,6 @@
 import { ffprobe, FfprobeData } from 'fluent-ffmpeg'
-import { VideoFileMetadata } from '@shared/models/videos'
+import { forceNumber } from '@shared/core-utils'
+import { VideoFileMetadata, VideoResolution } from '@shared/models/videos'
 
 /**
  *
@@ -55,7 +56,7 @@ async function getAudioStream (videoPath: string, existingProbe?: FfprobeData) {
       return {
         absolutePath: data.format.filename,
         audioStream,
-        bitrate: parseInt(audioStream['bit_rate'] + '', 10)
+        bitrate: forceNumber(audioStream['bit_rate'])
       }
     }
   }
@@ -103,7 +104,15 @@ function getMaxAudioBitrate (type: 'aac' | 'mp3' | string, bitrate: number) {
 
 async function getVideoStreamDimensionsInfo (path: string, existingProbe?: FfprobeData) {
   const videoStream = await getVideoStream(path, existingProbe)
-  if (!videoStream) return undefined
+  if (!videoStream) {
+    return {
+      width: 0,
+      height: 0,
+      ratio: 0,
+      resolution: VideoResolution.H_NOVIDEO,
+      isPortraitMode: false
+    }
+  }
 
   return {
     width: videoStream.width,