From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 9B83B4474F for ; Thu, 22 Sep 2022 14:08:29 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4D42E68BBBD; Thu, 22 Sep 2022 17:08:27 +0300 (EEST) Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id F14FD68BA40 for ; Thu, 22 Sep 2022 17:08:20 +0300 (EEST) Received: by mail-wm1-f42.google.com with SMTP id k3-20020a05600c1c8300b003b4fa1a85f8so1418867wms.3 for ; Thu, 22 Sep 2022 07:08:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date; bh=bx8qkqJ2rF8eTwKk8mwGMP01XowySIyOnCbnQ5OTlSg=; b=Pyzff2LbwjCcSeFK8ZF9n4oM52JP2vDM1g5O9u8Zl1lOo9Zs3onWS5bihmSu0DSAyn kPGuL2vcPcN1eCljc3q+3JslPewtxadT3hG8uTjv2X65pnZMGsAe9OtTEOkVdGmEB/Lm Z3+SjyMOWzFRJkKqhWSemiZBOLyeAB5AeG+sZ/3Gh1wH7D7ORgQpFUAVyWPssFezHoeV rgmXXzgDjYAs2P5i42ZL2dHrfa0KF3OsflqDhnNACJA8MAQb38QduC2Hot1MSffC1Iuz RrYmLQFy9mOgVdVxfFhwVJNf4QjxV7E+LC9wXHT4FaEcWrawQN4Gok/qED29/s5eBbJ3 5IVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date; bh=bx8qkqJ2rF8eTwKk8mwGMP01XowySIyOnCbnQ5OTlSg=; b=daGGh5VUX6QvrhPmHO8L03u9+3qETU1b2k6a/vYy/eNMrxTC39fBQ2gewEB8MfJchi /rVWzOynvA+X4XzV5z0Lb+/Da59cZvcy3H0gQ3p+8IW/aLDXhQyn7GEjZLJC9JuihgRY SsdCFF1WrFh/rSiofuz0cRNk3lUMnd/u6zl1qN6T97n7lqMu/JRKTSwPyvrgg6Mtjf6n Pk25Vsza7SrJcRSf9JHWK8LRUhb6HX3C6qnPS0oniz2TEkJGvpxS+Sfmu1t06vPJ2Vgd IfbDFRdVZtBm1JluLppkPR4WEmSW31jkwQs3Mr1ZXclCM4dxP23vbY1oHFuj5NG4xzxn mh1g== X-Gm-Message-State: ACrzQf0xr5+CV/RSSXIYTpXo8LvRXasVuXgCVUDTv+HhvM6rXsJy80Ez lWiiBWdw+ZrMGPn7UbGZX2I/cYXoN2Q= X-Google-Smtp-Source: AMsMyM51S5UCgMs+dT5FUp5s/kPPsW7kqPsgW+1dwJ5Jyp2jw68Q/Wd73kg7c4oBcdDh7nJFr494RA== X-Received: by 2002:a05:600c:a47:b0:3a6:5848:4bde with SMTP id c7-20020a05600c0a4700b003a658484bdemr9445533wmq.189.1663855700024; Thu, 22 Sep 2022 07:08:20 -0700 (PDT) Received: from localhost.localdomain ([149.12.10.163]) by smtp.gmail.com with ESMTPSA id u9-20020a056000038900b002252884cc91sm5017985wrf.43.2022.09.22.07.08.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Sep 2022 07:08:19 -0700 (PDT) From: Derek Buitenhuis To: ffmpeg-devel@ffmpeg.org Date: Thu, 22 Sep 2022 15:08:00 +0100 Message-Id: <20220922140800.240449-1-derek.buitenhuis@gmail.com> X-Mailer: git-send-email 2.37.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2] ffprobe: Check for invalid matrix error when printing rotation X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: av_display_rotation_get will return NAN when the display matrix is invalid, which would end up printing NAN as an integer in the rotation field. This is poor for multiple reasons: * Users of ffprobe have no way of discerning "valid but ugly rotation from display matrix" from "invalid display matrix". * It can have unintended consequences on some platforms, such as Linux x86_64, where NAN is equal to INT64_MIN, which, for example, when printed as JSON, which uses floating point for all numbers, can end up as invalid JSON or wit a number that cannot be reserialized as an integer at all. Since NAN is av_display_rotation_get's error case, just print 0 (no rotation) when that happens. Signed-off-by: Derek Buitenhuis --- I could have also changed av_display_rotation_get to return 0, but I didn't want to make an API change. Arguably, though, returning NAN on error isn't an amazing API to begin with. v2 now with typo fix and proper NAN checks. --- fftools/ffprobe.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c index 8ee1b1036c..421ada5bd8 100644 --- a/fftools/ffprobe.c +++ b/fftools/ffprobe.c @@ -27,6 +27,7 @@ #include "libavutil/ffversion.h" #include +#include #include "libavformat/avformat.h" #include "libavformat/version.h" @@ -2282,8 +2283,11 @@ static void print_pkt_side_data(WriterContext *w, writer_print_section_header(w, id_data); print_str("side_data_type", name ? name : "unknown"); if (sd->type == AV_PKT_DATA_DISPLAYMATRIX && sd->size >= 9*4) { + double rotation = av_display_rotation_get((int32_t *)sd->data); + if (isnan(rotation)) + rotation = 0; writer_print_integers(w, "displaymatrix", sd->data, 9, " %11d", 3, 4, 1); - print_int("rotation", av_display_rotation_get((int32_t *)sd->data)); + print_int("rotation", rotation); } else if (sd->type == AV_PKT_DATA_STEREO3D) { const AVStereo3D *stereo = (AVStereo3D *)sd->data; print_str("type", av_stereo3d_type_name(stereo->type)); @@ -2639,8 +2643,11 @@ static void show_frame(WriterContext *w, AVFrame *frame, AVStream *stream, name = av_frame_side_data_name(sd->type); print_str("side_data_type", name ? name : "unknown"); if (sd->type == AV_FRAME_DATA_DISPLAYMATRIX && sd->size >= 9*4) { + double rotation = av_display_rotation_get((int32_t *)sd->data); + if (isnan(rotation)) + rotation = 0; writer_print_integers(w, "displaymatrix", sd->data, 9, " %11d", 3, 4, 1); - print_int("rotation", av_display_rotation_get((int32_t *)sd->data)); + print_int("rotation", rotation); } else if (sd->type == AV_FRAME_DATA_AFD && sd->size > 0) { print_int("active_format", *sd->data); } else if (sd->type == AV_FRAME_DATA_GOP_TIMECODE && sd->size >= 8) { -- 2.37.2 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".