From d6122736161715f75c1588ce4792c473e90042d8 Mon Sep 17 00:00:00 2001 From: Oneric Date: Wed, 8 Feb 2023 20:53:35 +0100 Subject: [PATCH 1/8] gui: clarify LayoutRes{X,Y} overriding GUI setting The GUI settings only define the default behaviour for files without LayoutRes{X,Y} headers. Backported from: https://github.com/Cyberbeing/xy-VSFilter/commit/1ca5e4bfa4e9ac09806f2fffa44b8a4297d2f8e0 --- src/filters/transform/vsfilter/VSFilter.rc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/filters/transform/vsfilter/VSFilter.rc b/src/filters/transform/vsfilter/VSFilter.rc index c6f8351d..af43b928 100644 --- a/src/filters/transform/vsfilter/VSFilter.rc +++ b/src/filters/transform/vsfilter/VSFilter.rc @@ -374,7 +374,7 @@ BEGIN RTEXT "Cache LV2",IDC_LABEL_OVERLAY_NO_BLUR,20,56,57,8 PUSHBUTTON "caches info",IDC_CACHES_INFO_BTN,147,21,50,14 COMBOBOX IDC_COMBO_LAYOUT_SIZE_OPT,27,106,74,64,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP - GROUPBOX "Renderer Layout Options",IDC_STATIC,7,97,233,27 + GROUPBOX "Renderer Layout Default",IDC_STATIC,7,97,233,27 LTEXT "H:",IDC_STATIC,112,107,9,8 LTEXT "V:",IDC_STATIC,157,107,8,8 EDITTEXT IDC_EDIT_LAYOUT_SIZE_X,122,107,32,12,ES_RIGHT | ES_AUTOHSCROLL | ES_NUMBER From ebd0f025d70d52ed96a5d3f983b01bb7c77cdca4 Mon Sep 17 00:00:00 2001 From: Oneric Date: Mon, 20 Feb 2023 11:36:00 +0100 Subject: [PATCH 2/8] Include License in nightly builds Backported from: https://github.com/Cyberbeing/xy-VSFilter/commit/532b756999bb1ee55afcc6631084ab70257831bd --- .github/workflows/build.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3cd91bae..e3f3d3d2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -73,6 +73,7 @@ jobs: run: | export VS160COMNTOOLS="C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/Common7/Tools/" bash ./build_vsfilter.sh -platform "${{ matrix.vsfplat }}" -compiler VS2019 + cp License.txt bin/ - name: Prune incompatible files if: steps.config.outputs.delete != '' @@ -89,3 +90,4 @@ jobs: name: xy-${{ steps.config.outputs.name }}_nightly_${{ matrix.namesuf }} path: | bin/lib*/*/Release + bin/License.txt From 97b0372a3e8b2823930a4483bbf99c6aab402163 Mon Sep 17 00:00:00 2001 From: Masaiki Date: Mon, 22 Aug 2022 22:11:30 +0800 Subject: [PATCH 3/8] feat: add some checks to avoid crashes Backported from: https://github.com/Cyberbeing/xy-VSFilter/commit/04afcbd244f79319b5bc97e7f8f8e8791519c0c1 --- src/subtitles/HdmvSub.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/subtitles/HdmvSub.cpp b/src/subtitles/HdmvSub.cpp index 87dd406a..fefeb4f7 100644 --- a/src/subtitles/HdmvSub.cpp +++ b/src/subtitles/HdmvSub.cpp @@ -208,6 +208,10 @@ HRESULT CHdmvSub::ParseSample(BYTE* pData, int lSampleLen, REFERENCE_TIME rtStar int CHdmvSub::ParsePresentationSegment(REFERENCE_TIME rt, CGolombBuffer* pGBuffer) { + if (pGBuffer->RemainingSize() < 11) { + return 0; + } + m_pCurrentPresentationSegment = DEBUG_NEW HDMV_PRESENTATION_SEGMENT(); m_pCurrentPresentationSegment->rtStart = rt; @@ -222,6 +226,10 @@ int CHdmvSub::ParsePresentationSegment(REFERENCE_TIME rt, CGolombBuffer* pGBuffe TRACE_HDMVSUB( (_T("CHdmvSub::ParsePresentationSegment Size = %d, state = %#x, nObjectNumber = %d\n"), pGBuffer->GetSize(), m_pCurrentPresentationSegment->composition_descriptor.bState, m_pCurrentPresentationSegment->objectCount) ); + if (pGBuffer->RemainingSize() < (m_pCurrentPresentationSegment->objectCount * 8)) { + return 0; + } + for (int i = 0; i < m_pCurrentPresentationSegment->objectCount; i++) { CompositionObject* pCompositionObject = DEBUG_NEW CompositionObject(); ParseCompositionObject(pGBuffer, pCompositionObject); @@ -287,7 +295,11 @@ void CHdmvSub::ParsePalette(CGolombBuffer* pGBuffer, unsigned short nSize) // # void CHdmvSub::ParseObject(CGolombBuffer* pGBuffer, unsigned short nUnitSize) // #498 { short object_id = pGBuffer->ReadShort(); - ASSERT(object_id < _countof(m_compositionObjects)); + + if (object_id >= _countof(m_compositionObjects)) { + TRACE_HDMVSUB((_T("CHdmvSub::ParseObject() : FAILED, object_id - %d"), object_id)); + return; + } CompositionObject& pObject = m_compositionObjects[object_id]; From 7e998295d4e01e709fa25de89bb9e04eec371838 Mon Sep 17 00:00:00 2001 From: Masaiki Date: Sun, 28 Aug 2022 16:06:06 +0800 Subject: [PATCH 4/8] fix: close sup file and read stop time of sample Backported from: https://github.com/Cyberbeing/xy-VSFilter/commit/41a8bee6349babeef7e5ae605115a460ba9736bb --- src/subtitles/hdmv_subtitle_provider.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/subtitles/hdmv_subtitle_provider.cpp b/src/subtitles/hdmv_subtitle_provider.cpp index ba0f44ea..19bd9bc8 100644 --- a/src/subtitles/hdmv_subtitle_provider.cpp +++ b/src/subtitles/hdmv_subtitle_provider.cpp @@ -472,22 +472,25 @@ DWORD SupFileSubtitleProvider::ThreadProc() while ((len = f.Read(buff, sizeof(buff))) > 0) { sub.Write(buff, len); } + f.Close(); sub.SeekToBegin(); WORD sync = 0; USHORT size = 0; REFERENCE_TIME rtStart = 0; + REFERENCE_TIME rtStop = 0; CAutoLock cAutoLock(&m_csCritSec); while (sub.GetPosition() < (sub.GetLength() - 10)) { sync = (WORD)ReadByte(&sub, 2); if (sync == 'PG') { rtStart = UINT64(ReadByte(&sub, 4) * (1000 / 9)); - sub.Seek(4 + 1, CFile::current); // rtStop + Segment type + rtStop = UINT64(ReadByte(&sub, 4) * (1000 / 9)); + sub.Seek(1, CFile::current); // Segment type size = ReadByte(&sub, 2) + 3; // Segment size sub.Seek(-3, CFile::current); sub.Read(buff, size); - m_pSub->ParseSample(buff, size, rtStart, 0); + m_pSub->ParseSample(buff, size, rtStart, rtStop); } else { break; } From 03abaaf43398c1ef2d47db092e92bebf6f3276de Mon Sep 17 00:00:00 2001 From: Masaiki Date: Tue, 30 Aug 2022 23:17:15 +0800 Subject: [PATCH 5/8] fix: time shift when playing external sup files Backported from: https://github.com/Cyberbeing/xy-VSFilter/commit/fee81a6d1abc6276c51115b6ef28475609b83540 --- src/subtitles/hdmv_subtitle_provider.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/subtitles/hdmv_subtitle_provider.cpp b/src/subtitles/hdmv_subtitle_provider.cpp index 19bd9bc8..9ca9f6b9 100644 --- a/src/subtitles/hdmv_subtitle_provider.cpp +++ b/src/subtitles/hdmv_subtitle_provider.cpp @@ -484,8 +484,8 @@ DWORD SupFileSubtitleProvider::ThreadProc() while (sub.GetPosition() < (sub.GetLength() - 10)) { sync = (WORD)ReadByte(&sub, 2); if (sync == 'PG') { - rtStart = UINT64(ReadByte(&sub, 4) * (1000 / 9)); - rtStop = UINT64(ReadByte(&sub, 4) * (1000 / 9)); + rtStart = UINT64(ReadByte(&sub, 4) * 1000 / 9); + rtStop = UINT64(ReadByte(&sub, 4) * 1000 / 9); sub.Seek(1, CFile::current); // Segment type size = ReadByte(&sub, 2) + 3; // Segment size sub.Seek(-3, CFile::current); From 6a0e81ea32c53bf80773350be83cf714f39b7776 Mon Sep 17 00:00:00 2001 From: Cyberbeing Date: Fri, 2 May 2014 14:27:50 -0700 Subject: [PATCH 6/8] Update CSRI name Backported from: https://github.com/Cyberbeing/xy-VSFilter/commit/0d64ad7bc03ab26d68150670ef92f3105b24ee20 (2014-10-19) --- src/filters/transform/vsfilter/csriapi.cpp | 54 +++++----------------- 1 file changed, 12 insertions(+), 42 deletions(-) diff --git a/src/filters/transform/vsfilter/csriapi.cpp b/src/filters/transform/vsfilter/csriapi.cpp index 83a24a94..b032db02 100644 --- a/src/filters/transform/vsfilter/csriapi.cpp +++ b/src/filters/transform/vsfilter/csriapi.cpp @@ -107,10 +107,9 @@ CSRIAPI void csri_close(csri_inst *inst) CSRIAPI int csri_request_fmt(csri_inst *inst, const struct csri_fmt *fmt) { - if (!inst) return -1; - - if (!fmt->width || !fmt->height) + if (!inst || !fmt->width || !fmt->height) { return -1; + } // Check if pixel format is supported switch (fmt->pixfmt) { @@ -159,51 +158,22 @@ CSRIAPI void csri_render(csri_inst *inst, struct csri_frame *frame, double time) // No extensions supported -CSRIAPI void *csri_query_ext(csri_rend *rend, csri_ext_id extname) -{ - return 0; -} +CSRIAPI void *csri_query_ext(csri_rend *rend, csri_ext_id extname) { return 0; } // Get info for renderer static struct csri_info csri_vsfilter_info = { #ifdef _DEBUG - "vsfilter_textsub_debug", // name - "2.39", // version (assumed version number, svn revision, patchlevel) + "xy-vsfilter_textsub_debug", // name #else - "vsfilter_textsub", // name - "2.39", // version (assumed version number, svn revision, patchlevel) + "xy-vsfilter_textsub", // name #endif - // 2.38-0611 is base svn 611 - // 2.38-0611-1 is with clipfix and fax/fay patch - // 2.38-0611-2 adds CSRI - // 2.38-0611-3 fixes a bug in CSRI and adds fontcrash-fix and float-pos - // 2.38-0611-4 fixes be1-dots and ugly-fade bugs and adds xbord/ybord/xshad/yshad/blur tags and extends be - // 2.39 merges with guliverkli2 fork - "VSFilter/TextSub (guliverkli2)", // longname + "3.0", // version + "xy-VSFilter/TextSub", // longname "Gabest", // author - "Copyright (c) 2003-2008 by Gabest and others" // copyright + "Copyright (c) 2003-2014 by Gabest et al." // copyright }; -CSRIAPI struct csri_info *csri_renderer_info(csri_rend *rend) -{ - return &csri_vsfilter_info; -} -// Only one supported, obviously -CSRIAPI csri_rend *csri_renderer_byname(const char *name, const char *specific) -{ - if (strcmp(name, csri_vsfilter_info.name)) - return 0; - if (specific && strcmp(specific, csri_vsfilter_info.specific)) - return 0; - return &csri_vsfilter; -} -// Still just one -CSRIAPI csri_rend *csri_renderer_default() -{ - return &csri_vsfilter; -} -// And no further -CSRIAPI csri_rend *csri_renderer_next(csri_rend *prev) -{ - return 0; -} +CSRIAPI struct csri_info *csri_renderer_info(csri_rend *rend) { return &csri_vsfilter_info; } +CSRIAPI csri_rend *csri_renderer_byname(const char *name, const char *specific) { return &csri_vsfilter; } +CSRIAPI csri_rend *csri_renderer_default() { return &csri_vsfilter; } +CSRIAPI csri_rend *csri_renderer_next(csri_rend *prev) { return 0; } From 4845a6a803eaaecc409b47995c8de26352c658c4 Mon Sep 17 00:00:00 2001 From: Oneric Date: Mon, 20 Feb 2023 14:22:26 +0100 Subject: [PATCH 7/8] Use distinct CSRI name and update CSRI version MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Similar to the preceeding commit backported from Cyberbeing/xy-VSFilter, let’s adjust the name so users can distinguish Cyberbeing/xy-VSFilter from pinterf/xy-VSFilter if say builds from both are placed into Aegisub’s csri directory. Latest releases are numbered 3.2.x.x, so update the version advertised in CSRI to match. --- src/filters/transform/vsfilter/csriapi.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/filters/transform/vsfilter/csriapi.cpp b/src/filters/transform/vsfilter/csriapi.cpp index b032db02..b967ac6a 100644 --- a/src/filters/transform/vsfilter/csriapi.cpp +++ b/src/filters/transform/vsfilter/csriapi.cpp @@ -163,11 +163,11 @@ CSRIAPI void *csri_query_ext(csri_rend *rend, csri_ext_id extname) { return 0; } // Get info for renderer static struct csri_info csri_vsfilter_info = { #ifdef _DEBUG - "xy-vsfilter_textsub_debug", // name + "pf-xy-vsfilter_textsub_debug", // name #else - "xy-vsfilter_textsub", // name + "pf-xy-vsfilter_textsub", // name #endif - "3.0", // version + "3.2", // version "xy-VSFilter/TextSub", // longname "Gabest", // author "Copyright (c) 2003-2014 by Gabest et al." // copyright From 102897189902658ec68ef691eb3dd8d89f099985 Mon Sep 17 00:00:00 2001 From: Oneric Date: Fri, 8 Dec 2023 15:56:11 +0100 Subject: [PATCH 8/8] Gracefully handle negative Encoding values Back in 2012 libass added a custom Encoding=-1 extension to enable automatic BiDi base direction instead of the usual LTR default. The assumption/hope presumably was that since all valid font encodings are positive VSFilter would just gracefully ignore them. However, this is unfortuantely not the case. When passed to GDI the charSet is cast to a byte and will wrap around to a valid value, severely restricting which fonts can be used. Searching through a large pile of subtitles the only hits for negative values in the Encoding field were from generally corrupted files. It thus appears so far fortunately nobody used the extension in released fiels (only transient conversion from other formats during playback) and also nobody is relying on the wraparound in VSFilter. To minimise future problems treat all negative Encodings as the default charset. This matches how libass does fontselection for -1 albeit it doesn't reproduce the BiDi base direction. It also conveniently carves out the [-2, INT_MIN] range for potential future extensions common to VSFilters and libass, e.g. Encoding=-2 for a RTL base direction (which should be easier to implement in VSFilter than auto base direction) --- src/subtitles/RTS.cpp | 1 + src/subtitles/STS.cpp | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/subtitles/RTS.cpp b/src/subtitles/RTS.cpp index 9fae771f..e1a958ad 100644 --- a/src/subtitles/RTS.cpp +++ b/src/subtitles/RTS.cpp @@ -2415,6 +2415,7 @@ bool CRenderedTextSubtitle::ParseSSATag( CSubtitle* sub, const AssTagList& assTa case CMD_fe: { int n = wcstol(p, NULL, 10); + if (n < 0) n = DEFAULT_CHARSET; style.charSet = !p.IsEmpty() ? n : org.charSet; diff --git a/src/subtitles/STS.cpp b/src/subtitles/STS.cpp index a1a4c9cb..b8650cb5 100644 --- a/src/subtitles/STS.cpp +++ b/src/subtitles/STS.cpp @@ -1978,6 +1978,7 @@ static bool OpenSubStationAlpha(CTextFile* file, CSimpleTextSubtitle& ret, int C { CString StyleName; int alpha; + int encoding; CRect tmp_rect; StyleName = GetStr(buff); @@ -2002,9 +2003,11 @@ if(sver >= 4) style->borderStyle = GetInt(buff); if(sver >= 6) tmp_rect.bottom = GetInt(buff); style->marginRect = tmp_rect; if(sver <= 4) alpha = GetInt(buff); - style->charSet = GetInt(buff); + encoding = GetInt(buff); if(sver >= 6) style->relativeTo = GetInt(buff); + // Map unsupported extension to the most permissive charSet + style->charSet = encoding < 0 ? DEFAULT_CHARSET : encoding; if(sver <= 4) style->colors[2] = style->colors[3]; // style->colors[2] is used for drawing the outline if(sver <= 4) alpha = max(min(alpha, 0xff), 0); if(sver <= 4) {for(size_t i = 0; i < 3; i++) style->alpha[i] = alpha; style->alpha[3] = 0x80;}