From 56feb1ecca224399b168c9776aafa8373e50abdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Sat, 8 Apr 2023 13:25:58 +0200 Subject: [PATCH 1/5] [protobuf] update overlay/osx to 3.21.12#1 --- overlay/osx/protobuf/compile_options.patch | 48 ++++++++++++++++++ .../fix-default-proto-file-path.patch | 7 +-- overlay/osx/protobuf/fix-static-build.patch | 8 +-- overlay/osx/protobuf/port_def.patch | 14 ------ overlay/osx/protobuf/portfile.cmake | 49 ++++++++++--------- .../osx/protobuf/vcpkg-cmake-wrapper.cmake | 2 +- overlay/osx/protobuf/vcpkg.json | 13 ++++- 7 files changed, 93 insertions(+), 48 deletions(-) create mode 100644 overlay/osx/protobuf/compile_options.patch delete mode 100644 overlay/osx/protobuf/port_def.patch diff --git a/overlay/osx/protobuf/compile_options.patch b/overlay/osx/protobuf/compile_options.patch new file mode 100644 index 00000000000000..8cf5417740f27e --- /dev/null +++ b/overlay/osx/protobuf/compile_options.patch @@ -0,0 +1,48 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 04cb3303a..608c580be 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -242,12 +242,12 @@ endif (protobuf_BUILD_SHARED_LIBS) + if (MSVC) + if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + # Build with multiple processes +- add_definitions(/MP) ++ add_compile_options(/MP) + endif() + # Set source file and execution character sets to UTF-8 +- add_definitions(/utf-8) ++ add_compile_options(/utf-8) + # MSVC warning suppressions +- add_definitions( ++ add_compile_options( + /wd4065 # switch statement contains 'default' but no 'case' labels + /wd4244 # 'conversion' conversion from 'type1' to 'type2', possible loss of data + /wd4251 # 'identifier' : class 'type' needs to have dll-interface to be used by clients of class 'type2' +@@ -262,23 +262,17 @@ if (MSVC) + /wd4996 # The compiler encountered a deprecated declaration. + ) + # Allow big object +- add_definitions(/bigobj) ++ add_compile_options(/bigobj) + string(REPLACE "/" "\\" PROTOBUF_SOURCE_WIN32_PATH ${protobuf_SOURCE_DIR}) + string(REPLACE "/" "\\" PROTOBUF_BINARY_WIN32_PATH ${protobuf_BINARY_DIR}) + string(REPLACE "." "," protobuf_RC_FILEVERSION "${protobuf_VERSION}") + configure_file(${protobuf_SOURCE_DIR}/cmake/extract_includes.bat.in extract_includes.bat) + + # Suppress linker warnings about files with no symbols defined. +- set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} /ignore:4221") ++ string(APPEND CMAKE_STATIC_LINKER_FLAGS " /ignore:4221") + +- if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") +- # Configure Resource Compiler +- enable_language(RC) +- # use English language (0x409) in resource compiler +- set(rc_flags "/l0x409") +- # fix rc.exe invocations because of usage of add_definitions() +- set(CMAKE_RC_COMPILE_OBJECT " ${rc_flags} /fo ") +- endif() ++ # use English language (0x409) in resource compiler ++ string(APPEND CMAKE_RC_FLAGS " -l0x409") + + # Generate the version.rc file used elsewhere. + configure_file(${protobuf_SOURCE_DIR}/cmake/version.rc.in ${CMAKE_CURRENT_BINARY_DIR}/version.rc @ONLY) diff --git a/overlay/osx/protobuf/fix-default-proto-file-path.patch b/overlay/osx/protobuf/fix-default-proto-file-path.patch index a5af918b32786c..1c850b1dec2b97 100644 --- a/overlay/osx/protobuf/fix-default-proto-file-path.patch +++ b/overlay/osx/protobuf/fix-default-proto-file-path.patch @@ -1,11 +1,12 @@ diff --git a/src/google/protobuf/compiler/command_line_interface.cc b/src/google/protobuf/compiler/command_line_interface.cc -index f192ae6..22900ed 100644 +index 5e9a2c4..8eaa6e0 100644 --- a/src/google/protobuf/compiler/command_line_interface.cc +++ b/src/google/protobuf/compiler/command_line_interface.cc -@@ -260,11 +260,15 @@ void AddDefaultProtoPaths( +@@ -261,12 +261,15 @@ void AddDefaultProtoPaths( + std::pair("", path + "/include")); return; } - // Check if the upper level directory has an "include" subdirectory. +- // Check if the upper level directory has an "include" subdirectory. + // change "'$/bin' is next to 'include'" assumption to "'$/bin/tools' is next to 'include'" + for (int i = 0; i < 2; i++) + { diff --git a/overlay/osx/protobuf/fix-static-build.patch b/overlay/osx/protobuf/fix-static-build.patch index 0ba4982fe6f84e..496c6c4d50524b 100644 --- a/overlay/osx/protobuf/fix-static-build.patch +++ b/overlay/osx/protobuf/fix-static-build.patch @@ -1,11 +1,11 @@ diff --git a/cmake/install.cmake b/cmake/install.cmake -index 4091bc8..9850018 100644 +index 825cb25..4f453d6 100644 --- a/cmake/install.cmake +++ b/cmake/install.cmake -@@ -31,7 +31,7 @@ endforeach() - if (protobuf_BUILD_PROTOC_BINARIES) +@@ -32,7 +32,7 @@ if (protobuf_BUILD_PROTOC_BINARIES) install(TARGETS protoc EXPORT protobuf-targets - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT protoc) + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT protoc + BUNDLE DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT protoc) - if (UNIX AND NOT APPLE) + if (UNIX AND NOT APPLE AND NOT protobuf_MSVC_STATIC_RUNTIME) set_property(TARGET protoc diff --git a/overlay/osx/protobuf/port_def.patch b/overlay/osx/protobuf/port_def.patch deleted file mode 100644 index 31d71531d0aeaa..00000000000000 --- a/overlay/osx/protobuf/port_def.patch +++ /dev/null @@ -1,14 +0,0 @@ -diff --git a/src/google/protobuf/port_def.inc b/src/google/protobuf/port_def.inc -index f7b64a080..3493d9082 100644 ---- a/src/google/protobuf/port_def.inc -+++ b/src/google/protobuf/port_def.inc -@@ -564,7 +564,8 @@ - - // Our use of constinit does not yet work with GCC: - // https://github.com/protocolbuffers/protobuf/issues/8310 --#if defined(__cpp_constinit) && !defined(__GNUC__) -+// Does not work yet with Visual Studio 2019 Update 16.10 -+#if defined(__cpp_constinit) && !defined(__GNUC__) && !defined(_MSC_VER) - #define PROTOBUF_CONSTINIT constinit - #elif defined(__has_cpp_attribute) - #if __has_cpp_attribute(clang::require_constant_initialization) diff --git a/overlay/osx/protobuf/portfile.cmake b/overlay/osx/protobuf/portfile.cmake index eec54a641b4006..198574faa1e2f2 100644 --- a/overlay/osx/protobuf/portfile.cmake +++ b/overlay/osx/protobuf/portfile.cmake @@ -1,13 +1,15 @@ +vcpkg_minimum_required(VERSION 2022-10-12) # for ${VERSION} + vcpkg_from_github( OUT_SOURCE_PATH SOURCE_PATH REPO protocolbuffers/protobuf - REF 436bd7880e458532901c58f4d9d1ea23fa7edd52 #v3.15.8 - SHA512 88bb9a965bccfe11a07aee2c0c16eb9cc1845ea2d7500ef6def3e1c0a8155ac4eadd0ceef4b12552960dffe95a0fc82549d1abba71ca073ab86ec5de57d9cafb + REF v3.21.12 + SHA512 152f8441c325e808b942153c15e82fdb533d5273b50c25c28916ec568ada880f79242bb61ee332ac5fb0d20f21239ed6f8de02ef6256cc574b1fc354d002c6b0 HEAD_REF master PATCHES fix-static-build.patch fix-default-proto-file-path.patch - port_def.patch + compile_options.patch ) string(COMPARE EQUAL "${TARGET_TRIPLET}" "${HOST_TRIPLET}" protobuf_BUILD_PROTOC_BINARIES) @@ -27,7 +29,7 @@ endif() if (VCPKG_DOWNLOAD_MODE) # download PKGCONFIG in download mode which is used in `vcpkg_fixup_pkgconfig()` at the end of this script. - # download it here because `vcpkg_configure_cmake()` halts execution in download mode when running configure process. + # download it here because `vcpkg_cmake_configure()` halts execution in download mode when running configure process. vcpkg_find_acquire_program(PKGCONFIG) endif() @@ -40,9 +42,8 @@ if(${VCPKG_LIBRARY_LINKAGE} STREQUAL "static") ) endif() -vcpkg_configure_cmake( - SOURCE_PATH ${SOURCE_PATH}/cmake - PREFER_NINJA +vcpkg_cmake_configure( + SOURCE_PATH "${SOURCE_PATH}" OPTIONS -Dprotobuf_BUILD_SHARED_LIBS=${protobuf_BUILD_SHARED_LIBS} -Dprotobuf_MSVC_STATIC_RUNTIME=${protobuf_MSVC_STATIC_RUNTIME} @@ -54,7 +55,7 @@ vcpkg_configure_cmake( ${FEATURE_OPTIONS} ) -vcpkg_install_cmake() +vcpkg_cmake_install() # It appears that at this point the build hasn't actually finished. There is probably # a process spawned by the build, therefore we need to wait a bit. @@ -67,52 +68,52 @@ function(protobuf_try_remove_recurse_wait PATH_TO_REMOVE) endif() endfunction() -protobuf_try_remove_recurse_wait(${CURRENT_PACKAGES_DIR}/debug/include) +protobuf_try_remove_recurse_wait("${CURRENT_PACKAGES_DIR}/debug/include") if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release") - vcpkg_replace_string(${CURRENT_PACKAGES_DIR}/share/protobuf/protobuf-targets-release.cmake + vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/share/protobuf/protobuf-targets-release.cmake" "\${_IMPORT_PREFIX}/bin/protoc${VCPKG_HOST_EXECUTABLE_SUFFIX}" "\${_IMPORT_PREFIX}/tools/protobuf/protoc${VCPKG_HOST_EXECUTABLE_SUFFIX}" ) endif() if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug") - file(READ ${CURRENT_PACKAGES_DIR}/debug/share/protobuf/protobuf-targets-debug.cmake DEBUG_MODULE) + file(READ "${CURRENT_PACKAGES_DIR}/debug/share/protobuf/protobuf-targets-debug.cmake" DEBUG_MODULE) string(REPLACE "\${_IMPORT_PREFIX}" "\${_IMPORT_PREFIX}/debug" DEBUG_MODULE "${DEBUG_MODULE}") string(REPLACE "\${_IMPORT_PREFIX}/debug/bin/protoc${EXECUTABLE_SUFFIX}" "\${_IMPORT_PREFIX}/tools/protobuf/protoc${EXECUTABLE_SUFFIX}" DEBUG_MODULE "${DEBUG_MODULE}") - file(WRITE ${CURRENT_PACKAGES_DIR}/share/protobuf/protobuf-targets-debug.cmake "${DEBUG_MODULE}") + file(WRITE "${CURRENT_PACKAGES_DIR}/share/protobuf/protobuf-targets-debug.cmake" "${DEBUG_MODULE}") endif() -protobuf_try_remove_recurse_wait(${CURRENT_PACKAGES_DIR}/debug/share) +protobuf_try_remove_recurse_wait("${CURRENT_PACKAGES_DIR}/debug/share") if(protobuf_BUILD_PROTOC_BINARIES) if(VCPKG_TARGET_IS_WINDOWS) vcpkg_copy_tools(TOOL_NAMES protoc AUTO_CLEAN) else() - vcpkg_copy_tools(TOOL_NAMES protoc protoc-3.15.8.0 AUTO_CLEAN) + vcpkg_copy_tools(TOOL_NAMES protoc protoc-${VERSION}.0 AUTO_CLEAN) endif() else() - file(COPY ${CURRENT_HOST_INSTALLED_DIR}/tools/${PORT} DESTINATION ${CURRENT_PACKAGES_DIR}/tools) + file(COPY "${CURRENT_HOST_INSTALLED_DIR}/tools/${PORT}" DESTINATION "${CURRENT_PACKAGES_DIR}/tools") endif() -vcpkg_replace_string(${CURRENT_PACKAGES_DIR}/share/${PORT}/protobuf-config.cmake +vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/share/${PORT}/protobuf-config.cmake" "if(protobuf_MODULE_COMPATIBLE)" "if(ON)" ) if(NOT protobuf_BUILD_LIBPROTOC) - vcpkg_replace_string(${CURRENT_PACKAGES_DIR}/share/${PORT}/protobuf-module.cmake + vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/share/${PORT}/protobuf-module.cmake" "_protobuf_find_libraries(Protobuf_PROTOC protoc)" "" ) endif() if(VCPKG_LIBRARY_LINKAGE STREQUAL "static") - protobuf_try_remove_recurse_wait(${CURRENT_PACKAGES_DIR}/bin) - protobuf_try_remove_recurse_wait(${CURRENT_PACKAGES_DIR}/debug/bin) + protobuf_try_remove_recurse_wait("${CURRENT_PACKAGES_DIR}/bin") + protobuf_try_remove_recurse_wait("${CURRENT_PACKAGES_DIR}/debug/bin") endif() if(VCPKG_LIBRARY_LINKAGE STREQUAL "dynamic") - vcpkg_replace_string(${CURRENT_PACKAGES_DIR}/include/google/protobuf/stubs/platform_macros.h + vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/include/google/protobuf/stubs/platform_macros.h" "\#endif // GOOGLE_PROTOBUF_PLATFORM_MACROS_H_" "\#ifndef PROTOBUF_USE_DLLS\n\#define PROTOBUF_USE_DLLS\n\#endif // PROTOBUF_USE_DLLS\n\n\#endif // GOOGLE_PROTOBUF_PLATFORM_MACROS_H_" ) @@ -121,7 +122,7 @@ endif() vcpkg_copy_pdbs() set(packages protobuf protobuf-lite) foreach(_package IN LISTS packages) - set(_file ${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig/${_package}.pc) + set(_file "${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig/${_package}.pc") if(EXISTS "${_file}") vcpkg_replace_string(${_file} "-l${_package}" "-l${_package}d") endif() @@ -130,8 +131,8 @@ endforeach() vcpkg_fixup_pkgconfig() if(NOT protobuf_BUILD_PROTOC_BINARIES) - configure_file(${CMAKE_CURRENT_LIST_DIR}/protobuf-targets-vcpkg-protoc.cmake ${CURRENT_PACKAGES_DIR}/share/${PORT}/protobuf-targets-vcpkg-protoc.cmake COPYONLY) + configure_file("${CMAKE_CURRENT_LIST_DIR}/protobuf-targets-vcpkg-protoc.cmake" "${CURRENT_PACKAGES_DIR}/share/${PORT}/protobuf-targets-vcpkg-protoc.cmake" COPYONLY) endif() -configure_file(${CMAKE_CURRENT_LIST_DIR}/vcpkg-cmake-wrapper.cmake ${CURRENT_PACKAGES_DIR}/share/${PORT}/vcpkg-cmake-wrapper.cmake @ONLY) -file(INSTALL ${SOURCE_PATH}/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright) +configure_file("${CMAKE_CURRENT_LIST_DIR}/vcpkg-cmake-wrapper.cmake" "${CURRENT_PACKAGES_DIR}/share/${PORT}/vcpkg-cmake-wrapper.cmake" @ONLY) +file(INSTALL "${SOURCE_PATH}/LICENSE" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright) diff --git a/overlay/osx/protobuf/vcpkg-cmake-wrapper.cmake b/overlay/osx/protobuf/vcpkg-cmake-wrapper.cmake index 7269aedcca508f..542a16c2b8a300 100644 --- a/overlay/osx/protobuf/vcpkg-cmake-wrapper.cmake +++ b/overlay/osx/protobuf/vcpkg-cmake-wrapper.cmake @@ -11,6 +11,6 @@ if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.3) cmake_policy(POP) endif() -find_program(Protobuf_PROTOC_EXECUTABLE NAMES protoc PATHS "${CMAKE_CURRENT_LIST_DIR}/../../tools/protobuf" NO_DEFAULT_PATH) +find_program(Protobuf_PROTOC_EXECUTABLE NAMES protoc PATHS "${CMAKE_CURRENT_LIST_DIR}/../../../@HOST_TRIPLET@/tools/protobuf" NO_DEFAULT_PATH) _find_package(${ARGS}) diff --git a/overlay/osx/protobuf/vcpkg.json b/overlay/osx/protobuf/vcpkg.json index 89ef7e67192991..61344a19bff1a0 100644 --- a/overlay/osx/protobuf/vcpkg.json +++ b/overlay/osx/protobuf/vcpkg.json @@ -1,13 +1,22 @@ { "name": "protobuf", - "version-semver": "3.15.8", - "port-version": 5, + "version": "3.21.12", + "port-version": 1, "description": "Protocol Buffers - Google's data interchange format", "homepage": "https://github.com/protocolbuffers/protobuf", + "license": "BSD-3-Clause", "dependencies": [ { "name": "protobuf", "host": true + }, + { + "name": "vcpkg-cmake", + "host": true + }, + { + "name": "vcpkg-cmake-config", + "host": true } ], "features": { From 465d1370a0581b01d318978b18ec82cc10d817d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Sat, 8 Apr 2023 13:27:07 +0200 Subject: [PATCH 2/5] [libusb] update overlay/ports to 1.0.26.11791#1 --- overlay/ports/libusb/portfile.cmake | 47 ++++++++++++++--------------- overlay/ports/libusb/usage | 4 +-- overlay/ports/libusb/vcpkg.json | 6 ++-- 3 files changed, 27 insertions(+), 30 deletions(-) diff --git a/overlay/ports/libusb/portfile.cmake b/overlay/ports/libusb/portfile.cmake index c8334dc1e9f9f3..5b7cbadebd0926 100644 --- a/overlay/ports/libusb/portfile.cmake +++ b/overlay/ports/libusb/portfile.cmake @@ -6,37 +6,34 @@ set(VERSION 1.0.26) vcpkg_from_github( OUT_SOURCE_PATH SOURCE_PATH REPO libusb/libusb - REF 4239bc3a50014b8e6a5a2a59df1fff3b7469543b # v1.0.26 - SHA512 f07ec9ef4df555733dab9388595cd10bc87195da54f4c646478d4a0496ee7b8933de03e957c7466291c120102d8801e8b26846cb27b201bb9cbca5df03f3a6ef + REF fcf0c710ef5911ae37fbbf1b39d48a89f6f14e8a # v1.0.26.11791 2023-03-12 + SHA512 0aa6439f7988487adf2a3bff473fec80b5c722a47f117a60696d2aa25c87cc3f20fb6aaca7c66e49be25db6a35eb0bb5f71ed7b211d1b8ee064c5d7f1b985c73 HEAD_REF master ) -if(VCPKG_TARGET_IS_WINDOWS AND NOT VCPKG_TARGET_IS_MINGW) - if(VCPKG_PLATFORM_TOOLSET MATCHES "v142") - set(MSVS_VERSION 2019) - elseif(VCPKG_PLATFORM_TOOLSET MATCHES "v141") - set(MSVS_VERSION 2017) - else() - set(MSVS_VERSION 2015) - endif() +function(replace_runtime_library PROJ_FILE) + if (VCPKG_CRT_LINKAGE STREQUAL static) + file(READ "${PROJ_FILE}" PROJ_CONTENT) + string(REPLACE "MultiThreadedDLL" "MultiThreaded" PROJ_CONTENT "${PROJ_CONTENT}") + string(REPLACE "MultiThreadedDebugDLL" "MultiThreadedDebug" PROJ_CONTENT "${PROJ_CONTENT}") + file(WRITE "${PROJ_FILE}" "${PROJ_CONTENT}") + else() + file(READ "${PROJ_FILE}" PROJ_CONTENT) + string(REPLACE "MultiThreaded" "MultiThreadedDLL" PROJ_CONTENT "${PROJ_CONTENT}") + string(REPLACE "MultiThreadedDebug" "MultiThreadedDebugDLL" PROJ_CONTENT "${PROJ_CONTENT}") + file(WRITE "${PROJ_FILE}" "${PROJ_CONTENT}") + endif() +endfunction(replace_runtime_library) +if(VCPKG_TARGET_IS_WINDOWS AND NOT VCPKG_TARGET_IS_MINGW) if(VCPKG_LIBRARY_LINKAGE STREQUAL "dynamic") set(LIBUSB_PROJECT_TYPE dll) - if (VCPKG_CRT_LINKAGE STREQUAL static) - file(READ "${SOURCE_PATH}/msvc/libusb_${LIBUSB_PROJECT_TYPE}_${MSVS_VERSION}.vcxproj" PROJ_FILE) - string(REPLACE "MultiThreadedDLL" "MultiThreaded" PROJ_FILE "${PROJ_FILE}") - string(REPLACE "MultiThreadedDebugDLL" "MultiThreadedDebug" PROJ_FILE "${PROJ_FILE}") - file(WRITE "${SOURCE_PATH}/msvc/libusb_${LIBUSB_PROJECT_TYPE}_${MSVS_VERSION}.vcxproj" "${PROJ_FILE}") - endif() else() set(LIBUSB_PROJECT_TYPE static) - if (VCPKG_CRT_LINKAGE STREQUAL dynamic) - file(READ "${SOURCE_PATH}/msvc/libusb_${LIBUSB_PROJECT_TYPE}_${MSVS_VERSION}.vcxproj" PROJ_FILE) - string(REPLACE "MultiThreaded" "MultiThreadedDLL" PROJ_FILE "${PROJ_FILE}") - string(REPLACE "MultiThreadedDebug" "MultiThreadedDebugDLL" PROJ_FILE "${PROJ_FILE}") - file(WRITE "${SOURCE_PATH}/msvc/libusb_${LIBUSB_PROJECT_TYPE}_${MSVS_VERSION}.vcxproj" "${PROJ_FILE}") - endif() endif() + replace_runtime_library("${SOURCE_PATH}/msvc/Configuration.Base.props") + replace_runtime_library("${SOURCE_PATH}/msvc/Configuration.DynamicLibrary.props") + replace_runtime_library("${SOURCE_PATH}/msvc/Configuration.StaticLibrary.props") # The README.md file in the archive is a symlink to README # which causes issues with the windows MSBUILD process @@ -44,7 +41,7 @@ if(VCPKG_TARGET_IS_WINDOWS AND NOT VCPKG_TARGET_IS_MINGW) vcpkg_install_msbuild( SOURCE_PATH "${SOURCE_PATH}" - PROJECT_SUBPATH msvc/libusb_${LIBUSB_PROJECT_TYPE}_${MSVS_VERSION}.vcxproj + PROJECT_SUBPATH msvc/libusb_${LIBUSB_PROJECT_TYPE}.vcxproj LICENSE_SUBPATH COPYING ) file(INSTALL "${SOURCE_PATH}/libusb/libusb.h" DESTINATION "${CURRENT_PACKAGES_DIR}/include/libusb-1.0") @@ -67,5 +64,5 @@ endif() vcpkg_fixup_pkgconfig() -configure_file("${CURRENT_PORT_DIR}/usage" "${CURRENT_PACKAGES_DIR}/share/${PORT}/usage" @ONLY) -file(INSTALL "${SOURCE_PATH}/COPYING" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright) +file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}") +vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/COPYING") diff --git a/overlay/ports/libusb/usage b/overlay/ports/libusb/usage index de236d46ad389c..b61e18c68a0d2d 100644 --- a/overlay/ports/libusb/usage +++ b/overlay/ports/libusb/usage @@ -1,5 +1,5 @@ -The package @PORT@:@TARGET_TRIPLET@ provides CMake targets: +libusb provides CMake targets: - find_package(@PORT@ CONFIG REQUIRED) + find_package(libusb CONFIG REQUIRED) target_include_directories(main PRIVATE ${LIBUSB_INCLUDE_DIRS}) target_link_libraries(main PRIVATE ${LIBUSB_LIBRARIES}) diff --git a/overlay/ports/libusb/vcpkg.json b/overlay/ports/libusb/vcpkg.json index d0d81e099336c3..05e41dad17ce33 100644 --- a/overlay/ports/libusb/vcpkg.json +++ b/overlay/ports/libusb/vcpkg.json @@ -1,9 +1,9 @@ { "name": "libusb", - "version": "1.0.26", - "port-version": 3, + "version": "1.0.26.11791", + "port-version": 1, "description": "a cross-platform library to access USB devices", "homepage": "https://github.com/libusb/libusb", - "license": "LGPL-2.1", + "license": "LGPL-2.1-or-later", "supports": "!uwp" } From 74c0d86a3e68ccc74c16456c98b7c1d36dc1ad88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Sat, 8 Apr 2023 13:28:58 +0200 Subject: [PATCH 3/5] [portaudio] update overlay/ports to v19.7.0+2023-04-04 --- overlay/ports/portaudio/portfile.cmake | 40 +++++++++++++++++--------- overlay/ports/portaudio/vcpkg.json | 3 +- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/overlay/ports/portaudio/portfile.cmake b/overlay/ports/portaudio/portfile.cmake index 0bae36e62c5b4b..c68b6d34f1cae9 100644 --- a/overlay/ports/portaudio/portfile.cmake +++ b/overlay/ports/portaudio/portfile.cmake @@ -1,32 +1,46 @@ vcpkg_from_github( OUT_SOURCE_PATH SOURCE_PATH - REPO Be-ing/portaudio - REF 3364bca3c01a0aedf64ba5a5abeb8e7019717ffc - SHA512 ce67f3e32cd55c02f4966735b39e329016a6723de3e8eedde87254df6b22a4eaa7f2fcc99729125a1baff52dea35cb4664a3dec26805fe75425a167371963aaf - HEAD_REF jack_windows + REPO PortAudio/portaudio + REF c8b9dd2dfc1c12230f172876a0117f42d32e48b2 + SHA512 8aa489de52c40068dc87c7a6b89e5b2fd4d10f57f69b800796c6f5e2c0db71a8094a85a06b4168d6d164a79d868b28adfd525ca4e7a8d3a0193a94face569b65 ) +string(COMPARE EQUAL ${VCPKG_LIBRARY_LINKAGE} dynamic PA_BUILD_SHARED) +string(COMPARE EQUAL ${VCPKG_LIBRARY_LINKAGE} static PA_BUILD_STATIC) + vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS FEATURES - asio ASIO - jack JACK + asio PA_USE_ASIO + jack PA_USE_JACK ) -vcpkg_cmake_configure( +vcpkg_configure_cmake( SOURCE_PATH ${SOURCE_PATH} - OPTIONS ${FEATURE_OPTIONS} - # The ASIO variable is only used on Windows. - MAYBE_UNUSED_VARIABLES ASIO - OPTIONS_DEBUG -DDEBUG_OUTPUT:BOOL=ON + OPTIONS + ${FEATURE_OPTIONS} + -DPA_USE_DS=ON + -DPA_USE_WASAPI=ON + -DPA_USE_WDMKS=ON + -DPA_USE_WMME=ON + -DPA_LIBNAME_ADD_SUFFIX=OFF + -DPA_BUILD_SHARED=${PA_BUILD_SHARED} + -DPA_BUILD_STATIC=${PA_BUILD_STATIC} + -DPA_DLL_LINK_WITH_STATIC_RUNTIME=OFF + OPTIONS_DEBUG + -DPA_ENABLE_DEBUG_OUTPUT:BOOL=ON ) -vcpkg_cmake_install() -vcpkg_cmake_config_fixup(CONFIG_PATH "lib/cmake/${PORT}") +vcpkg_install_cmake() +vcpkg_fixup_cmake_targets(CONFIG_PATH "lib/cmake/${PORT}") vcpkg_fixup_pkgconfig() vcpkg_copy_pdbs() file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include") file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/share") +if(VCPKG_LIBRARY_LINKAGE STREQUAL static) + file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/bin ${CURRENT_PACKAGES_DIR}/debug/bin) +endif() + # Handle copyright file(INSTALL "${SOURCE_PATH}/LICENSE.txt" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME "copyright") diff --git a/overlay/ports/portaudio/vcpkg.json b/overlay/ports/portaudio/vcpkg.json index e7896a4eb94391..e8b7d00753e80a 100644 --- a/overlay/ports/portaudio/vcpkg.json +++ b/overlay/ports/portaudio/vcpkg.json @@ -1,7 +1,6 @@ { "name": "portaudio", - "version-date": "2021-08-05", - "port-version": 1, + "version-date": "2023-04-04", "description": "PortAudio Portable Cross-platform Audio I/O API PortAudio is a free, cross-platform, open-source, audio I/O library. It lets you write simple audio programs in 'C' or C++ that will compile and run on many platforms including Windows, Macintosh OS X, and Unix (OSS/ALSA). It is intended to promote the exchange of audio software between developers on different platforms. Many applications use PortAudio for Audio I/O.", "homepage": "https://app.assembla.com/spaces/portaudio/wiki", "license": "MIT", From 849247d68f07b417d882d6bbe35d8f4bf23b6b8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Tue, 2 May 2023 20:38:00 +0200 Subject: [PATCH 4/5] [libmad] Move to overlay/ports --- overlay/ports/libmad/0001-Fix-MSVC-ARM.patch | 25 +++++++++ overlay/ports/libmad/CMakeLists.txt | 53 ++++++++++++++++++++ overlay/ports/libmad/portfile.cmake | 27 ++++++++++ overlay/ports/libmad/vcpkg.json | 13 +++++ 4 files changed, 118 insertions(+) create mode 100644 overlay/ports/libmad/0001-Fix-MSVC-ARM.patch create mode 100644 overlay/ports/libmad/CMakeLists.txt create mode 100644 overlay/ports/libmad/portfile.cmake create mode 100644 overlay/ports/libmad/vcpkg.json diff --git a/overlay/ports/libmad/0001-Fix-MSVC-ARM.patch b/overlay/ports/libmad/0001-Fix-MSVC-ARM.patch new file mode 100644 index 00000000000000..9cdc57c7bfeea4 --- /dev/null +++ b/overlay/ports/libmad/0001-Fix-MSVC-ARM.patch @@ -0,0 +1,25 @@ +diff --git a/mad.h b/mad.h +index 9ef6cc8..5e3f7aa 100644 +--- a/mad.h ++++ b/mad.h +@@ -24,7 +24,11 @@ + extern "C" { + # endif + ++#ifdef _WIN64 ++# define FPM_64BIT ++#else + # define FPM_INTEL ++#endif + + + +@@ -184,7 +188,7 @@ typedef mad_fixed_t mad_sample_t; + + # elif defined(FPM_INTEL) + +-# if defined(_MSC_VER) ++# if defined(_MSC_VER) && defined(_M_IX86) + # pragma warning(push) + # pragma warning(disable: 4035) /* no return value */ + static __forceinline diff --git a/overlay/ports/libmad/CMakeLists.txt b/overlay/ports/libmad/CMakeLists.txt new file mode 100644 index 00000000000000..47db84c419fd47 --- /dev/null +++ b/overlay/ports/libmad/CMakeLists.txt @@ -0,0 +1,53 @@ +cmake_minimum_required(VERSION 2.8) + +project(libmad) + +set(SOURCES + bit.c + bit.h + config.h + decoder.c + decoder.h + fixed.c + fixed.h + frame.c + frame.h + global.h + huffman.c + huffman.h + layer12.c + layer12.h + layer3.c + layer3.h + mad.h + stream.c + stream.h + synth.c + synth.h + timer.c + timer.h + version.c + version.h +) + +add_library( + mad + ${SOURCES} +) + +target_compile_definitions(mad + PRIVATE _LIB _MBCS ASO_ZEROCHECK HAVE_CONFIG_H FPM_DEFAULT + PRIVATE _CRT_SECURE_NO_WARNINGS +) + +install( + TARGETS mad + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib +) + +install( + FILES mad.h + DESTINATION include +) diff --git a/overlay/ports/libmad/portfile.cmake b/overlay/ports/libmad/portfile.cmake new file mode 100644 index 00000000000000..5981c3598a87fa --- /dev/null +++ b/overlay/ports/libmad/portfile.cmake @@ -0,0 +1,27 @@ +vcpkg_check_linkage(ONLY_STATIC_LIBRARY) + +vcpkg_from_sourceforge( + OUT_SOURCE_PATH SOURCE_PATH + REPO mad/libmad + REF 0.15.1b + FILENAME "libmad-0.15.1b.tar.gz" + SHA512 2cad30347fb310dc605c46bacd9da117f447a5cabedd8fefdb24ab5de641429e5ec5ce8af7aefa6a75a3f545d3adfa255e3fa0a2d50971f76bc0c4fc0400cc45 + PATCHES 0001-Fix-MSVC-ARM.patch +) + +#The archive only contains a Visual Studio 6.0 era DSP project file, so use a custom CMakeLists.txt +file(COPY "${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt" DESTINATION "${SOURCE_PATH}") + +#Use the msvc++ config.h header +file(COPY "${SOURCE_PATH}/msvc++/config.h" DESTINATION "${SOURCE_PATH}") + +vcpkg_cmake_configure( + SOURCE_PATH "${SOURCE_PATH}" +) + +vcpkg_cmake_install() +vcpkg_copy_pdbs() + +file(INSTALL "${SOURCE_PATH}/COPYING" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright) + +file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include") diff --git a/overlay/ports/libmad/vcpkg.json b/overlay/ports/libmad/vcpkg.json new file mode 100644 index 00000000000000..9a03de492b3420 --- /dev/null +++ b/overlay/ports/libmad/vcpkg.json @@ -0,0 +1,13 @@ +{ + "name": "libmad", + "version-string": "0.15.1", + "port-version": 10, + "description": "high-quality MPEG audio decoder", + "homepage": "http://www.mars.org/home/rob/proj/mpeg/", + "dependencies": [ + { + "name": "vcpkg-cmake", + "host": true + } + ] +} From c76348b5c08175fbe30271d5da369499acfe3eb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Tue, 2 May 2023 20:53:52 +0200 Subject: [PATCH 5/5] [libmad] Added md_size.patch length-check.patch They are uses in the debian package to fix This bug: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=287519 --- overlay/ports/libmad/length-check.patch | 817 ++++++++++++++++++++++++ overlay/ports/libmad/md_size.patch | 58 ++ overlay/ports/libmad/portfile.cmake | 5 +- overlay/ports/libmad/vcpkg.json | 2 +- 4 files changed, 880 insertions(+), 2 deletions(-) create mode 100644 overlay/ports/libmad/length-check.patch create mode 100644 overlay/ports/libmad/md_size.patch diff --git a/overlay/ports/libmad/length-check.patch b/overlay/ports/libmad/length-check.patch new file mode 100644 index 00000000000000..80e48469e6523d --- /dev/null +++ b/overlay/ports/libmad/length-check.patch @@ -0,0 +1,817 @@ +From: Kurt Roeckx +Date: Sun, 28 Jan 2018 19:26:36 +0100 +Subject: Check the size before reading with mad_bit_read + +There are various cases where it attemps to read past the end of the buffer +using mad_bit_read(). Most functions didn't even know the size of the buffer +they were reading from. + +Index: libmad-0.15.1b/bit.c +=================================================================== +--- libmad-0.15.1b.orig/bit.c ++++ libmad-0.15.1b/bit.c +@@ -138,6 +138,9 @@ unsigned long mad_bit_read(struct mad_bi + { + register unsigned long value; + ++ if (len == 0) ++ return 0; ++ + if (bitptr->left == CHAR_BIT) + bitptr->cache = *bitptr->byte; + +Index: libmad-0.15.1b/frame.c +=================================================================== +--- libmad-0.15.1b.orig/frame.c ++++ libmad-0.15.1b/frame.c +@@ -120,11 +120,18 @@ static + int decode_header(struct mad_header *header, struct mad_stream *stream) + { + unsigned int index; ++ struct mad_bitptr bufend_ptr; + + header->flags = 0; + header->private_bits = 0; + ++ mad_bit_init(&bufend_ptr, stream->bufend); ++ + /* header() */ ++ if (mad_bit_length(&stream->ptr, &bufend_ptr) < 32) { ++ stream->error = MAD_ERROR_BUFLEN; ++ return -1; ++ } + + /* syncword */ + mad_bit_skip(&stream->ptr, 11); +@@ -225,8 +232,13 @@ int decode_header(struct mad_header *hea + /* error_check() */ + + /* crc_check */ +- if (header->flags & MAD_FLAG_PROTECTION) ++ if (header->flags & MAD_FLAG_PROTECTION) { ++ if (mad_bit_length(&stream->ptr, &bufend_ptr) < 16) { ++ stream->error = MAD_ERROR_BUFLEN; ++ return -1; ++ } + header->crc_target = mad_bit_read(&stream->ptr, 16); ++ } + + return 0; + } +@@ -338,7 +350,7 @@ int mad_header_decode(struct mad_header + stream->error = MAD_ERROR_BUFLEN; + goto fail; + } +- else if (!(ptr[0] == 0xff && (ptr[1] & 0xe0) == 0xe0)) { ++ else if ((end - ptr >= 2) && !(ptr[0] == 0xff && (ptr[1] & 0xe0) == 0xe0)) { + /* mark point where frame sync word was expected */ + stream->this_frame = ptr; + stream->next_frame = ptr + 1; +@@ -361,6 +373,8 @@ int mad_header_decode(struct mad_header + ptr = mad_bit_nextbyte(&stream->ptr); + } + ++ stream->error = MAD_ERROR_NONE; ++ + /* begin processing */ + stream->this_frame = ptr; + stream->next_frame = ptr + 1; /* possibly bogus sync word */ +@@ -413,7 +427,7 @@ int mad_header_decode(struct mad_header + /* check that a valid frame header follows this frame */ + + ptr = stream->next_frame; +- if (!(ptr[0] == 0xff && (ptr[1] & 0xe0) == 0xe0)) { ++ if ((end - ptr >= 2) && !(ptr[0] == 0xff && (ptr[1] & 0xe0) == 0xe0)) { + ptr = stream->next_frame = stream->this_frame + 1; + goto sync; + } +Index: libmad-0.15.1b/layer12.c +=================================================================== +--- libmad-0.15.1b.orig/layer12.c ++++ libmad-0.15.1b/layer12.c +@@ -72,10 +72,18 @@ mad_fixed_t const linear_table[14] = { + * DESCRIPTION: decode one requantized Layer I sample from a bitstream + */ + static +-mad_fixed_t I_sample(struct mad_bitptr *ptr, unsigned int nb) ++mad_fixed_t I_sample(struct mad_bitptr *ptr, unsigned int nb, struct mad_stream *stream) + { + mad_fixed_t sample; ++ struct mad_bitptr frameend_ptr; + ++ mad_bit_init(&frameend_ptr, stream->next_frame); ++ ++ if (mad_bit_length(ptr, &frameend_ptr) < nb) { ++ stream->error = MAD_ERROR_LOSTSYNC; ++ stream->sync = 0; ++ return 0; ++ } + sample = mad_bit_read(ptr, nb); + + /* invert most significant bit, extend sign, then scale to fixed format */ +@@ -106,6 +114,10 @@ int mad_layer_I(struct mad_stream *strea + struct mad_header *header = &frame->header; + unsigned int nch, bound, ch, s, sb, nb; + unsigned char allocation[2][32], scalefactor[2][32]; ++ struct mad_bitptr bufend_ptr, frameend_ptr; ++ ++ mad_bit_init(&bufend_ptr, stream->bufend); ++ mad_bit_init(&frameend_ptr, stream->next_frame); + + nch = MAD_NCHANNELS(header); + +@@ -118,6 +130,11 @@ int mad_layer_I(struct mad_stream *strea + /* check CRC word */ + + if (header->flags & MAD_FLAG_PROTECTION) { ++ if (mad_bit_length(&stream->ptr, &bufend_ptr) ++ < 4 * (bound * nch + (32 - bound))) { ++ stream->error = MAD_ERROR_BADCRC; ++ return -1; ++ } + header->crc_check = + mad_bit_crc(stream->ptr, 4 * (bound * nch + (32 - bound)), + header->crc_check); +@@ -133,6 +150,11 @@ int mad_layer_I(struct mad_stream *strea + + for (sb = 0; sb < bound; ++sb) { + for (ch = 0; ch < nch; ++ch) { ++ if (mad_bit_length(&stream->ptr, &frameend_ptr) < 4) { ++ stream->error = MAD_ERROR_LOSTSYNC; ++ stream->sync = 0; ++ return -1; ++ } + nb = mad_bit_read(&stream->ptr, 4); + + if (nb == 15) { +@@ -145,6 +167,11 @@ int mad_layer_I(struct mad_stream *strea + } + + for (sb = bound; sb < 32; ++sb) { ++ if (mad_bit_length(&stream->ptr, &frameend_ptr) < 4) { ++ stream->error = MAD_ERROR_LOSTSYNC; ++ stream->sync = 0; ++ return -1; ++ } + nb = mad_bit_read(&stream->ptr, 4); + + if (nb == 15) { +@@ -161,6 +188,11 @@ int mad_layer_I(struct mad_stream *strea + for (sb = 0; sb < 32; ++sb) { + for (ch = 0; ch < nch; ++ch) { + if (allocation[ch][sb]) { ++ if (mad_bit_length(&stream->ptr, &frameend_ptr) < 6) { ++ stream->error = MAD_ERROR_LOSTSYNC; ++ stream->sync = 0; ++ return -1; ++ } + scalefactor[ch][sb] = mad_bit_read(&stream->ptr, 6); + + # if defined(OPT_STRICT) +@@ -185,8 +217,10 @@ int mad_layer_I(struct mad_stream *strea + for (ch = 0; ch < nch; ++ch) { + nb = allocation[ch][sb]; + frame->sbsample[ch][s][sb] = nb ? +- mad_f_mul(I_sample(&stream->ptr, nb), ++ mad_f_mul(I_sample(&stream->ptr, nb, stream), + sf_table[scalefactor[ch][sb]]) : 0; ++ if (stream->error != 0) ++ return -1; + } + } + +@@ -194,7 +228,14 @@ int mad_layer_I(struct mad_stream *strea + if ((nb = allocation[0][sb])) { + mad_fixed_t sample; + +- sample = I_sample(&stream->ptr, nb); ++ if (mad_bit_length(&stream->ptr, &frameend_ptr) < nb) { ++ stream->error = MAD_ERROR_LOSTSYNC; ++ stream->sync = 0; ++ return -1; ++ } ++ sample = I_sample(&stream->ptr, nb, stream); ++ if (stream->error != 0) ++ return -1; + + for (ch = 0; ch < nch; ++ch) { + frame->sbsample[ch][s][sb] = +@@ -280,13 +321,21 @@ struct quantclass { + static + void II_samples(struct mad_bitptr *ptr, + struct quantclass const *quantclass, +- mad_fixed_t output[3]) ++ mad_fixed_t output[3], struct mad_stream *stream) + { + unsigned int nb, s, sample[3]; ++ struct mad_bitptr frameend_ptr; ++ ++ mad_bit_init(&frameend_ptr, stream->next_frame); + + if ((nb = quantclass->group)) { + unsigned int c, nlevels; + ++ if (mad_bit_length(ptr, &frameend_ptr) < quantclass->bits) { ++ stream->error = MAD_ERROR_LOSTSYNC; ++ stream->sync = 0; ++ return; ++ } + /* degrouping */ + c = mad_bit_read(ptr, quantclass->bits); + nlevels = quantclass->nlevels; +@@ -299,8 +348,14 @@ void II_samples(struct mad_bitptr *ptr, + else { + nb = quantclass->bits; + +- for (s = 0; s < 3; ++s) ++ for (s = 0; s < 3; ++s) { ++ if (mad_bit_length(ptr, &frameend_ptr) < nb) { ++ stream->error = MAD_ERROR_LOSTSYNC; ++ stream->sync = 0; ++ return; ++ } + sample[s] = mad_bit_read(ptr, nb); ++ } + } + + for (s = 0; s < 3; ++s) { +@@ -336,6 +391,9 @@ int mad_layer_II(struct mad_stream *stre + unsigned char const *offsets; + unsigned char allocation[2][32], scfsi[2][32], scalefactor[2][32][3]; + mad_fixed_t samples[3]; ++ struct mad_bitptr frameend_ptr; ++ ++ mad_bit_init(&frameend_ptr, stream->next_frame); + + nch = MAD_NCHANNELS(header); + +@@ -402,13 +460,24 @@ int mad_layer_II(struct mad_stream *stre + for (sb = 0; sb < bound; ++sb) { + nbal = bitalloc_table[offsets[sb]].nbal; + +- for (ch = 0; ch < nch; ++ch) ++ for (ch = 0; ch < nch; ++ch) { ++ if (mad_bit_length(&stream->ptr, &frameend_ptr) < nbal) { ++ stream->error = MAD_ERROR_LOSTSYNC; ++ stream->sync = 0; ++ return -1; ++ } + allocation[ch][sb] = mad_bit_read(&stream->ptr, nbal); ++ } + } + + for (sb = bound; sb < sblimit; ++sb) { + nbal = bitalloc_table[offsets[sb]].nbal; + ++ if (mad_bit_length(&stream->ptr, &frameend_ptr) < nbal) { ++ stream->error = MAD_ERROR_LOSTSYNC; ++ stream->sync = 0; ++ return -1; ++ } + allocation[0][sb] = + allocation[1][sb] = mad_bit_read(&stream->ptr, nbal); + } +@@ -417,8 +486,14 @@ int mad_layer_II(struct mad_stream *stre + + for (sb = 0; sb < sblimit; ++sb) { + for (ch = 0; ch < nch; ++ch) { +- if (allocation[ch][sb]) ++ if (allocation[ch][sb]) { ++ if (mad_bit_length(&stream->ptr, &frameend_ptr) < 2) { ++ stream->error = MAD_ERROR_LOSTSYNC; ++ stream->sync = 0; ++ return -1; ++ } + scfsi[ch][sb] = mad_bit_read(&stream->ptr, 2); ++ } + } + } + +@@ -441,6 +516,11 @@ int mad_layer_II(struct mad_stream *stre + for (sb = 0; sb < sblimit; ++sb) { + for (ch = 0; ch < nch; ++ch) { + if (allocation[ch][sb]) { ++ if (mad_bit_length(&stream->ptr, &frameend_ptr) < 6) { ++ stream->error = MAD_ERROR_LOSTSYNC; ++ stream->sync = 0; ++ return -1; ++ } + scalefactor[ch][sb][0] = mad_bit_read(&stream->ptr, 6); + + switch (scfsi[ch][sb]) { +@@ -451,11 +531,21 @@ int mad_layer_II(struct mad_stream *stre + break; + + case 0: ++ if (mad_bit_length(&stream->ptr, &frameend_ptr) < 6) { ++ stream->error = MAD_ERROR_LOSTSYNC; ++ stream->sync = 0; ++ return -1; ++ } + scalefactor[ch][sb][1] = mad_bit_read(&stream->ptr, 6); + /* fall through */ + + case 1: + case 3: ++ if (mad_bit_length(&stream->ptr, &frameend_ptr) < 6) { ++ stream->error = MAD_ERROR_LOSTSYNC; ++ stream->sync = 0; ++ return -1; ++ } + scalefactor[ch][sb][2] = mad_bit_read(&stream->ptr, 6); + } + +@@ -487,7 +577,9 @@ int mad_layer_II(struct mad_stream *stre + if ((index = allocation[ch][sb])) { + index = offset_table[bitalloc_table[offsets[sb]].offset][index - 1]; + +- II_samples(&stream->ptr, &qc_table[index], samples); ++ II_samples(&stream->ptr, &qc_table[index], samples, stream); ++ if (stream->error != 0) ++ return -1; + + for (s = 0; s < 3; ++s) { + frame->sbsample[ch][3 * gr + s][sb] = +@@ -505,7 +597,9 @@ int mad_layer_II(struct mad_stream *stre + if ((index = allocation[0][sb])) { + index = offset_table[bitalloc_table[offsets[sb]].offset][index - 1]; + +- II_samples(&stream->ptr, &qc_table[index], samples); ++ II_samples(&stream->ptr, &qc_table[index], samples, stream); ++ if (stream->error != 0) ++ return -1; + + for (ch = 0; ch < nch; ++ch) { + for (s = 0; s < 3; ++s) { +Index: libmad-0.15.1b/layer3.c +=================================================================== +--- libmad-0.15.1b.orig/layer3.c ++++ libmad-0.15.1b/layer3.c +@@ -598,7 +598,8 @@ enum mad_error III_sideinfo(struct mad_b + static + unsigned int III_scalefactors_lsf(struct mad_bitptr *ptr, + struct channel *channel, +- struct channel *gr1ch, int mode_extension) ++ struct channel *gr1ch, int mode_extension, ++ unsigned int bits_left, unsigned int *part2_length) + { + struct mad_bitptr start; + unsigned int scalefac_compress, index, slen[4], part, n, i; +@@ -644,8 +645,12 @@ unsigned int III_scalefactors_lsf(struct + + n = 0; + for (part = 0; part < 4; ++part) { +- for (i = 0; i < nsfb[part]; ++i) ++ for (i = 0; i < nsfb[part]; ++i) { ++ if (bits_left < slen[part]) ++ return MAD_ERROR_BADSCFSI; + channel->scalefac[n++] = mad_bit_read(ptr, slen[part]); ++ bits_left -= slen[part]; ++ } + } + + while (n < 39) +@@ -690,7 +695,10 @@ unsigned int III_scalefactors_lsf(struct + max = (1 << slen[part]) - 1; + + for (i = 0; i < nsfb[part]; ++i) { ++ if (bits_left < slen[part]) ++ return MAD_ERROR_BADSCFSI; + is_pos = mad_bit_read(ptr, slen[part]); ++ bits_left -= slen[part]; + + channel->scalefac[n] = is_pos; + gr1ch->scalefac[n++] = (is_pos == max); +@@ -703,7 +711,8 @@ unsigned int III_scalefactors_lsf(struct + } + } + +- return mad_bit_length(&start, ptr); ++ *part2_length = mad_bit_length(&start, ptr); ++ return MAD_ERROR_NONE; + } + + /* +@@ -712,7 +721,8 @@ unsigned int III_scalefactors_lsf(struct + */ + static + unsigned int III_scalefactors(struct mad_bitptr *ptr, struct channel *channel, +- struct channel const *gr0ch, unsigned int scfsi) ++ struct channel const *gr0ch, unsigned int scfsi, ++ unsigned int bits_left, unsigned int *part2_length) + { + struct mad_bitptr start; + unsigned int slen1, slen2, sfbi; +@@ -728,12 +738,20 @@ unsigned int III_scalefactors(struct mad + sfbi = 0; + + nsfb = (channel->flags & mixed_block_flag) ? 8 + 3 * 3 : 6 * 3; +- while (nsfb--) ++ while (nsfb--) { ++ if (bits_left < slen1) ++ return MAD_ERROR_BADSCFSI; + channel->scalefac[sfbi++] = mad_bit_read(ptr, slen1); ++ bits_left -= slen1; ++ } + + nsfb = 6 * 3; +- while (nsfb--) ++ while (nsfb--) { ++ if (bits_left < slen2) ++ return MAD_ERROR_BADSCFSI; + channel->scalefac[sfbi++] = mad_bit_read(ptr, slen2); ++ bits_left -= slen2; ++ } + + nsfb = 1 * 3; + while (nsfb--) +@@ -745,8 +763,12 @@ unsigned int III_scalefactors(struct mad + channel->scalefac[sfbi] = gr0ch->scalefac[sfbi]; + } + else { +- for (sfbi = 0; sfbi < 6; ++sfbi) ++ for (sfbi = 0; sfbi < 6; ++sfbi) { ++ if (bits_left < slen1) ++ return MAD_ERROR_BADSCFSI; + channel->scalefac[sfbi] = mad_bit_read(ptr, slen1); ++ bits_left -= slen1; ++ } + } + + if (scfsi & 0x4) { +@@ -754,8 +776,12 @@ unsigned int III_scalefactors(struct mad + channel->scalefac[sfbi] = gr0ch->scalefac[sfbi]; + } + else { +- for (sfbi = 6; sfbi < 11; ++sfbi) ++ for (sfbi = 6; sfbi < 11; ++sfbi) { ++ if (bits_left < slen1) ++ return MAD_ERROR_BADSCFSI; + channel->scalefac[sfbi] = mad_bit_read(ptr, slen1); ++ bits_left -= slen1; ++ } + } + + if (scfsi & 0x2) { +@@ -763,8 +789,12 @@ unsigned int III_scalefactors(struct mad + channel->scalefac[sfbi] = gr0ch->scalefac[sfbi]; + } + else { +- for (sfbi = 11; sfbi < 16; ++sfbi) ++ for (sfbi = 11; sfbi < 16; ++sfbi) { ++ if (bits_left < slen2) ++ return MAD_ERROR_BADSCFSI; + channel->scalefac[sfbi] = mad_bit_read(ptr, slen2); ++ bits_left -= slen2; ++ } + } + + if (scfsi & 0x1) { +@@ -772,14 +802,19 @@ unsigned int III_scalefactors(struct mad + channel->scalefac[sfbi] = gr0ch->scalefac[sfbi]; + } + else { +- for (sfbi = 16; sfbi < 21; ++sfbi) ++ for (sfbi = 16; sfbi < 21; ++sfbi) { ++ if (bits_left < slen2) ++ return MAD_ERROR_BADSCFSI; + channel->scalefac[sfbi] = mad_bit_read(ptr, slen2); ++ bits_left -= slen2; ++ } + } + + channel->scalefac[21] = 0; + } + +- return mad_bit_length(&start, ptr); ++ *part2_length = mad_bit_length(&start, ptr); ++ return MAD_ERROR_NONE; + } + + /* +@@ -933,19 +968,17 @@ static + enum mad_error III_huffdecode(struct mad_bitptr *ptr, mad_fixed_t xr[576], + struct channel *channel, + unsigned char const *sfbwidth, +- unsigned int part2_length) ++ signed int part3_length) + { + signed int exponents[39], exp; + signed int const *expptr; + struct mad_bitptr peek; +- signed int bits_left, cachesz; ++ signed int bits_left, cachesz, fakebits; + register mad_fixed_t *xrptr; + mad_fixed_t const *sfbound; + register unsigned long bitcache; + +- bits_left = (signed) channel->part2_3_length - (signed) part2_length; +- if (bits_left < 0) +- return MAD_ERROR_BADPART3LEN; ++ bits_left = part3_length; + + III_exponents(channel, sfbwidth, exponents); + +@@ -956,8 +989,12 @@ enum mad_error III_huffdecode(struct mad + cachesz = mad_bit_bitsleft(&peek); + cachesz += ((32 - 1 - 24) + (24 - cachesz)) & ~7; + ++ if (bits_left < cachesz) { ++ cachesz = bits_left; ++ } + bitcache = mad_bit_read(&peek, cachesz); + bits_left -= cachesz; ++ fakebits = 0; + + xrptr = &xr[0]; + +@@ -986,7 +1023,7 @@ enum mad_error III_huffdecode(struct mad + + big_values = channel->big_values; + +- while (big_values-- && cachesz + bits_left > 0) { ++ while (big_values-- && cachesz + bits_left - fakebits > 0) { + union huffpair const *pair; + unsigned int clumpsz, value; + register mad_fixed_t requantized; +@@ -1023,10 +1060,19 @@ enum mad_error III_huffdecode(struct mad + unsigned int bits; + + bits = ((32 - 1 - 21) + (21 - cachesz)) & ~7; ++ if (bits_left < bits) { ++ bits = bits_left; ++ } + bitcache = (bitcache << bits) | mad_bit_read(&peek, bits); + cachesz += bits; + bits_left -= bits; + } ++ if (cachesz < 21) { ++ unsigned int bits = 21 - cachesz; ++ bitcache <<= bits; ++ cachesz += bits; ++ fakebits += bits; ++ } + + /* hcod (0..19) */ + +@@ -1041,6 +1087,8 @@ enum mad_error III_huffdecode(struct mad + } + + cachesz -= pair->value.hlen; ++ if (cachesz < fakebits) ++ return MAD_ERROR_BADHUFFDATA; + + if (linbits) { + /* x (0..14) */ +@@ -1054,10 +1102,15 @@ enum mad_error III_huffdecode(struct mad + + case 15: + if (cachesz < linbits + 2) { +- bitcache = (bitcache << 16) | mad_bit_read(&peek, 16); +- cachesz += 16; +- bits_left -= 16; ++ unsigned int bits = 16; ++ if (bits_left < 16) ++ bits = bits_left; ++ bitcache = (bitcache << bits) | mad_bit_read(&peek, bits); ++ cachesz += bits; ++ bits_left -= bits; + } ++ if (cachesz - fakebits < linbits) ++ return MAD_ERROR_BADHUFFDATA; + + value += MASK(bitcache, cachesz, linbits); + cachesz -= linbits; +@@ -1074,6 +1127,8 @@ enum mad_error III_huffdecode(struct mad + } + + x_final: ++ if (cachesz - fakebits < 1) ++ return MAD_ERROR_BADHUFFDATA; + xrptr[0] = MASK1BIT(bitcache, cachesz--) ? + -requantized : requantized; + } +@@ -1089,10 +1144,15 @@ enum mad_error III_huffdecode(struct mad + + case 15: + if (cachesz < linbits + 1) { +- bitcache = (bitcache << 16) | mad_bit_read(&peek, 16); +- cachesz += 16; +- bits_left -= 16; ++ unsigned int bits = 16; ++ if (bits_left < 16) ++ bits = bits_left; ++ bitcache = (bitcache << bits) | mad_bit_read(&peek, bits); ++ cachesz += bits; ++ bits_left -= bits; + } ++ if (cachesz - fakebits < linbits) ++ return MAD_ERROR_BADHUFFDATA; + + value += MASK(bitcache, cachesz, linbits); + cachesz -= linbits; +@@ -1109,6 +1169,8 @@ enum mad_error III_huffdecode(struct mad + } + + y_final: ++ if (cachesz - fakebits < 1) ++ return MAD_ERROR_BADHUFFDATA; + xrptr[1] = MASK1BIT(bitcache, cachesz--) ? + -requantized : requantized; + } +@@ -1128,6 +1190,8 @@ enum mad_error III_huffdecode(struct mad + requantized = reqcache[value] = III_requantize(value, exp); + } + ++ if (cachesz - fakebits < 1) ++ return MAD_ERROR_BADHUFFDATA; + xrptr[0] = MASK1BIT(bitcache, cachesz--) ? + -requantized : requantized; + } +@@ -1146,6 +1210,8 @@ enum mad_error III_huffdecode(struct mad + requantized = reqcache[value] = III_requantize(value, exp); + } + ++ if (cachesz - fakebits < 1) ++ return MAD_ERROR_BADHUFFDATA; + xrptr[1] = MASK1BIT(bitcache, cachesz--) ? + -requantized : requantized; + } +@@ -1155,9 +1221,6 @@ enum mad_error III_huffdecode(struct mad + } + } + +- if (cachesz + bits_left < 0) +- return MAD_ERROR_BADHUFFDATA; /* big_values overrun */ +- + /* count1 */ + { + union huffquad const *table; +@@ -1167,15 +1230,24 @@ enum mad_error III_huffdecode(struct mad + + requantized = III_requantize(1, exp); + +- while (cachesz + bits_left > 0 && xrptr <= &xr[572]) { ++ while (cachesz + bits_left - fakebits > 0 && xrptr <= &xr[572]) { + union huffquad const *quad; + + /* hcod (1..6) */ + + if (cachesz < 10) { +- bitcache = (bitcache << 16) | mad_bit_read(&peek, 16); +- cachesz += 16; +- bits_left -= 16; ++ unsigned int bits = 16; ++ if (bits_left < 16) ++ bits = bits_left; ++ bitcache = (bitcache << bits) | mad_bit_read(&peek, bits); ++ cachesz += bits; ++ bits_left -= bits; ++ } ++ if (cachesz < 10) { ++ unsigned int bits = 10 - cachesz; ++ bitcache <<= bits; ++ cachesz += bits; ++ fakebits += bits; + } + + quad = &table[MASK(bitcache, cachesz, 4)]; +@@ -1188,6 +1260,11 @@ enum mad_error III_huffdecode(struct mad + MASK(bitcache, cachesz, quad->ptr.bits)]; + } + ++ if (cachesz - fakebits < quad->value.hlen + quad->value.v ++ + quad->value.w + quad->value.x + quad->value.y) ++ /* We don't have enough bits to read one more entry, consider them ++ * stuffing bits. */ ++ break; + cachesz -= quad->value.hlen; + + if (xrptr == sfbound) { +@@ -1236,22 +1313,8 @@ enum mad_error III_huffdecode(struct mad + + xrptr += 2; + } +- +- if (cachesz + bits_left < 0) { +-# if 0 && defined(DEBUG) +- fprintf(stderr, "huffman count1 overrun (%d bits)\n", +- -(cachesz + bits_left)); +-# endif +- +- /* technically the bitstream is misformatted, but apparently +- some encoders are just a bit sloppy with stuffing bits */ +- +- xrptr -= 4; +- } + } + +- assert(-bits_left <= MAD_BUFFER_GUARD * CHAR_BIT); +- + # if 0 && defined(DEBUG) + if (bits_left < 0) + fprintf(stderr, "read %d bits too many\n", -bits_left); +@@ -2348,10 +2411,11 @@ void III_freqinver(mad_fixed_t sample[18 + */ + static + enum mad_error III_decode(struct mad_bitptr *ptr, struct mad_frame *frame, +- struct sideinfo *si, unsigned int nch) ++ struct sideinfo *si, unsigned int nch, unsigned int md_len) + { + struct mad_header *header = &frame->header; + unsigned int sfreqi, ngr, gr; ++ int bits_left = md_len * CHAR_BIT; + + { + unsigned int sfreq; +@@ -2383,6 +2447,7 @@ enum mad_error III_decode(struct mad_bit + for (ch = 0; ch < nch; ++ch) { + struct channel *channel = &granule->ch[ch]; + unsigned int part2_length; ++ unsigned int part3_length; + + sfbwidth[ch] = sfbwidth_table[sfreqi].l; + if (channel->block_type == 2) { +@@ -2391,18 +2456,30 @@ enum mad_error III_decode(struct mad_bit + } + + if (header->flags & MAD_FLAG_LSF_EXT) { +- part2_length = III_scalefactors_lsf(ptr, channel, ++ error = III_scalefactors_lsf(ptr, channel, + ch == 0 ? 0 : &si->gr[1].ch[1], +- header->mode_extension); ++ header->mode_extension, bits_left, &part2_length); + } + else { +- part2_length = III_scalefactors(ptr, channel, &si->gr[0].ch[ch], +- gr == 0 ? 0 : si->scfsi[ch]); ++ error = III_scalefactors(ptr, channel, &si->gr[0].ch[ch], ++ gr == 0 ? 0 : si->scfsi[ch], bits_left, &part2_length); + } ++ if (error) ++ return error; ++ ++ bits_left -= part2_length; + +- error = III_huffdecode(ptr, xr[ch], channel, sfbwidth[ch], part2_length); ++ if (part2_length > channel->part2_3_length) ++ return MAD_ERROR_BADPART3LEN; ++ ++ part3_length = channel->part2_3_length - part2_length; ++ if (part3_length > bits_left) ++ return MAD_ERROR_BADPART3LEN; ++ ++ error = III_huffdecode(ptr, xr[ch], channel, sfbwidth[ch], part3_length); + if (error) + return error; ++ bits_left -= part3_length; + } + + /* joint stereo processing */ +@@ -2519,11 +2596,13 @@ int mad_layer_III(struct mad_stream *str + unsigned int nch, priv_bitlen, next_md_begin = 0; + unsigned int si_len, data_bitlen, md_len; + unsigned int frame_space, frame_used, frame_free; +- struct mad_bitptr ptr; ++ struct mad_bitptr ptr, bufend_ptr; + struct sideinfo si; + enum mad_error error; + int result = 0; + ++ mad_bit_init(&bufend_ptr, stream->bufend); ++ + /* allocate Layer III dynamic structures */ + + if (stream->main_data == 0) { +@@ -2587,14 +2666,15 @@ int mad_layer_III(struct mad_stream *str + unsigned long header; + + mad_bit_init(&peek, stream->next_frame); ++ if (mad_bit_length(&peek, &bufend_ptr) >= 57) { ++ header = mad_bit_read(&peek, 32); ++ if ((header & 0xffe60000L) /* syncword | layer */ == 0xffe20000L) { ++ if (!(header & 0x00010000L)) /* protection_bit */ ++ mad_bit_skip(&peek, 16); /* crc_check */ + +- header = mad_bit_read(&peek, 32); +- if ((header & 0xffe60000L) /* syncword | layer */ == 0xffe20000L) { +- if (!(header & 0x00010000L)) /* protection_bit */ +- mad_bit_skip(&peek, 16); /* crc_check */ +- +- next_md_begin = +- mad_bit_read(&peek, (header & 0x00080000L) /* ID */ ? 9 : 8); ++ next_md_begin = ++ mad_bit_read(&peek, (header & 0x00080000L) /* ID */ ? 9 : 8); ++ } + } + + mad_bit_finish(&peek); +@@ -2653,7 +2733,7 @@ int mad_layer_III(struct mad_stream *str + /* decode main_data */ + + if (result == 0) { +- error = III_decode(&ptr, frame, &si, nch); ++ error = III_decode(&ptr, frame, &si, nch, md_len); + if (error) { + stream->error = error; + result = -1; diff --git a/overlay/ports/libmad/md_size.patch b/overlay/ports/libmad/md_size.patch new file mode 100644 index 00000000000000..657b5ffdb971e2 --- /dev/null +++ b/overlay/ports/libmad/md_size.patch @@ -0,0 +1,58 @@ +From: Kurt Roeckx +Date: Sun, 28 Jan 2018 15:44:08 +0100 +Subject: Check the size of the main data + +The main data to decode a frame can come from the current frame and part of the +previous frame, the so called bit reservoir. si.main_data_begin is the part of +the previous frame we need for this frame. frame_space is the amount of main +data that can be in this frame, and next_md_begin is the part of this frame that +is going to be used for the next frame. + +The maximum amount of data from a previous frame that the format allows is 511 +bytes. The maximum frame size for the defined bitrates is at MPEG 2.5 layer 2 +at 320 kbit/s and 8 kHz sample rate which gives 72 * (320000 / 8000) + 1 = 2881. +So those defines are not large enough: + # define MAD_BUFFER_GUARD 8 + # define MAD_BUFFER_MDLEN (511 + 2048 + MAD_BUFFER_GUARD) + +There is also support for a "free" bitrate which allows you to create any frame +size, which can be larger than the buffer. + +Changing the defines is not an option since it's part of the ABI, so we check +that the main data fits in the bufer. + +The previous frame data is stored in *stream->main_data and contains +stream->md_len bytes. If stream->md_len is larger than the data we +need from the previous frame (si.main_data_begin) it still wouldn't fit +in the buffer, so just keep the data that we need. + +Index: libmad-0.15.1b/layer3.c +=================================================================== +--- libmad-0.15.1b.orig/layer3.c ++++ libmad-0.15.1b/layer3.c +@@ -2608,6 +2608,11 @@ int mad_layer_III(struct mad_stream *str + next_md_begin = 0; + + md_len = si.main_data_begin + frame_space - next_md_begin; ++ if (md_len + MAD_BUFFER_GUARD > MAD_BUFFER_MDLEN) { ++ stream->error = MAD_ERROR_LOSTSYNC; ++ stream->sync = 0; ++ return -1; ++ } + + frame_used = 0; + +@@ -2625,8 +2630,11 @@ int mad_layer_III(struct mad_stream *str + } + } + else { +- mad_bit_init(&ptr, +- *stream->main_data + stream->md_len - si.main_data_begin); ++ memmove(stream->main_data, ++ *stream->main_data + stream->md_len - si.main_data_begin, ++ si.main_data_begin); ++ stream->md_len = si.main_data_begin; ++ mad_bit_init(&ptr, *stream->main_data); + + if (md_len > si.main_data_begin) { + assert(stream->md_len + md_len - diff --git a/overlay/ports/libmad/portfile.cmake b/overlay/ports/libmad/portfile.cmake index 5981c3598a87fa..ff1e3b1ac8dae0 100644 --- a/overlay/ports/libmad/portfile.cmake +++ b/overlay/ports/libmad/portfile.cmake @@ -6,7 +6,10 @@ vcpkg_from_sourceforge( REF 0.15.1b FILENAME "libmad-0.15.1b.tar.gz" SHA512 2cad30347fb310dc605c46bacd9da117f447a5cabedd8fefdb24ab5de641429e5ec5ce8af7aefa6a75a3f545d3adfa255e3fa0a2d50971f76bc0c4fc0400cc45 - PATCHES 0001-Fix-MSVC-ARM.patch + PATCHES + 0001-Fix-MSVC-ARM.patch + md_size.patch + length-check.patch ) #The archive only contains a Visual Studio 6.0 era DSP project file, so use a custom CMakeLists.txt diff --git a/overlay/ports/libmad/vcpkg.json b/overlay/ports/libmad/vcpkg.json index 9a03de492b3420..3dca7f437f526b 100644 --- a/overlay/ports/libmad/vcpkg.json +++ b/overlay/ports/libmad/vcpkg.json @@ -1,7 +1,7 @@ { "name": "libmad", "version-string": "0.15.1", - "port-version": 10, + "port-version": 11, "description": "high-quality MPEG audio decoder", "homepage": "http://www.mars.org/home/rob/proj/mpeg/", "dependencies": [