├── .gitignore ├── .gitattributes ├── patches ├── 04-remove_unsupported_description_option.diff ├── 01-replace_deprecated_compile_options.diff ├── 02-build_dll.diff └── 03-add_version_resource.diff ├── LICENSE ├── version.rc ├── CHANGES.md ├── README.md └── Build-Bzip2.ps1 /.gitignore: -------------------------------------------------------------------------------- 1 | outputs 2 | packages 3 | source -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | *.diff text eol=lf -------------------------------------------------------------------------------- /patches/04-remove_unsupported_description_option.diff: -------------------------------------------------------------------------------- 1 | --- bzip2-1.0.6.orig/libbz2.def Wed Jan 3 02:00:55 2007 2 | +++ bzip2-1.0.6/libbz2.def Sat Jan 24 20:38:03 2015 3 | @@ -1,5 +1,4 @@ 4 | LIBRARY LIBBZ2 5 | -DESCRIPTION "libbzip2: library for data compression" 6 | EXPORTS 7 | BZ2_bzCompressInit 8 | BZ2_bzCompress 9 | -------------------------------------------------------------------------------- /patches/01-replace_deprecated_compile_options.diff: -------------------------------------------------------------------------------- 1 | --- bzip2-1.0.6.orig/makefile.msc Wed Jan 3 02:00:55 2007 2 | +++ bzip2-1.0.6/makefile.msc Sat Jan 24 19:44:09 2015 3 | @@ -17,8 +17,8 @@ OBJS= blocksort.obj \ 4 | all: lib bzip2 test 5 | 6 | bzip2: lib 7 | - $(CC) $(CFLAGS) -o bzip2 bzip2.c libbz2.lib setargv.obj 8 | - $(CC) $(CFLAGS) -o bzip2recover bzip2recover.c 9 | + $(CC) $(CFLAGS) /Febzip2 bzip2.c libbz2.lib setargv.obj 10 | + $(CC) $(CFLAGS) /Febzip2recover bzip2recover.c 11 | 12 | lib: $(OBJS) 13 | lib /out:libbz2.lib $(OBJS) 14 | @@ -59,5 +59,5 @@ clean: 15 | del sample3.tst 16 | 17 | .c.obj: 18 | - $(CC) $(CFLAGS) -c $*.c -o $*.obj 19 | + $(CC) $(CFLAGS) -c $*.c /Fo$*.obj 20 | 21 | -------------------------------------------------------------------------------- /patches/02-build_dll.diff: -------------------------------------------------------------------------------- 1 | --- bzip2-1.0.6.orig/makefile.msc Sat Jan 24 19:44:09 2015 2 | +++ bzip2-1.0.6/makefile.msc Sat Jan 24 19:51:36 2015 3 | @@ -14,14 +14,17 @@ OBJS= blocksort.obj \ 4 | decompress.obj \ 5 | bzlib.obj 6 | 7 | -all: lib bzip2 test 8 | +all: dll lib bzip2 test 9 | 10 | -bzip2: lib 11 | +bzip2: dll 12 | $(CC) $(CFLAGS) /Febzip2 bzip2.c libbz2.lib setargv.obj 13 | $(CC) $(CFLAGS) /Febzip2recover bzip2recover.c 14 | 15 | +dll: $(OBJS) libbz2.def 16 | + link /dll /implib:libbz2.lib /out:libbz2.dll /def:libbz2.def $(OBJS) 17 | + 18 | lib: $(OBJS) 19 | - lib /out:libbz2.lib $(OBJS) 20 | + lib /out:libbz2-static.lib $(OBJS) 21 | 22 | test: bzip2 23 | type words1 24 | @@ -49,6 +52,9 @@ test: bzip2 25 | clean: 26 | del *.obj 27 | del libbz2.lib 28 | + del libbz2.dll 29 | + del libbz2.exp 30 | + del libbz2-static.lib 31 | del bzip2.exe 32 | del bzip2recover.exe 33 | del sample1.rb2 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015-2019 Philip Ross 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal in 5 | the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 7 | of the Software, and to permit persons to whom the Software is furnished to do 8 | so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /version.rc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | LANGUAGE 0x09,0x01 4 | 5 | 1 VERSIONINFO 6 | FILEVERSION 1,0,8,0 7 | PRODUCTVERSION 1,0,8,0 8 | FILEFLAGSMASK 0x3fL 9 | FILEFLAGS 0x00L 10 | FILEOS VOS__WINDOWS32 11 | #if defined(LIBBZ2) 12 | FILETYPE VFT_DLL 13 | #else 14 | FILETYPE VFT_APP 15 | #endif 16 | FILESUBTYPE 0x0L 17 | BEGIN 18 | BLOCK "StringFileInfo" 19 | BEGIN 20 | BLOCK "040904b0" 21 | BEGIN 22 | // VALUE "Comments", "\0" 23 | VALUE "CompanyName", "bzip2, https://www.sourceware.org/bzip2/\0" 24 | VALUE "FileDescription", "bzip2\0" 25 | VALUE "FileVersion", "1.0.8.0\0" 26 | #if defined(LIBBZ2) 27 | VALUE "InternalName", "libbz2\0" 28 | VALUE "OriginalFilename", "libbz2.dll\0" 29 | #elif defined(BZIP2) 30 | VALUE "InternalName", "bzip2\0" 31 | VALUE "OriginalFilename", "bzip2.exe\0" 32 | #elif defined(BZIP2RECOVER) 33 | VALUE "InternalName", "bzip2recover\0" 34 | VALUE "OriginalFilename", "bzip2recover.exe\0" 35 | #endif 36 | VALUE "LegalCopyright", "Copyright (C) 1996-2019 Julian Seward . All rights reserved.\0" 37 | // VALUE "LegalTrademarks", "\0" 38 | // VALUE "PrivateBuild", "\0" 39 | VALUE "ProductName", "bzip2\0" 40 | VALUE "ProductVersion", "1.0.8\0" 41 | // VALUE "SpecialBuild", "\0" 42 | END 43 | END 44 | BLOCK "VarFileInfo" 45 | BEGIN 46 | VALUE "Translation", 0x409, 0x4b0 47 | END 48 | END 49 | -------------------------------------------------------------------------------- /patches/03-add_version_resource.diff: -------------------------------------------------------------------------------- 1 | --- bzip2-1.0.6.orig/makefile.msc Sat Jan 24 19:51:36 2015 2 | +++ bzip2-1.0.6/makefile.msc Sun Jan 25 17:18:22 2015 3 | @@ -5,6 +5,7 @@ 4 | 5 | CC=cl 6 | CFLAGS= -DWIN32 -MD -Ox -D_FILE_OFFSET_BITS=64 -nologo 7 | +RC=rc 8 | 9 | OBJS= blocksort.obj \ 10 | huffman.obj \ 11 | @@ -16,16 +17,25 @@ OBJS= blocksort.obj \ 12 | 13 | all: dll lib bzip2 test 14 | 15 | -bzip2: dll 16 | - $(CC) $(CFLAGS) /Febzip2 bzip2.c libbz2.lib setargv.obj 17 | - $(CC) $(CFLAGS) /Febzip2recover bzip2recover.c 18 | +bzip2: dll bzip2.res bzip2recover.res 19 | + $(CC) $(CFLAGS) /Febzip2 bzip2.c libbz2.lib setargv.obj bzip2.res 20 | + $(CC) $(CFLAGS) /Febzip2recover bzip2recover.c bzip2recover.res 21 | 22 | -dll: $(OBJS) libbz2.def 23 | - link /dll /implib:libbz2.lib /out:libbz2.dll /def:libbz2.def $(OBJS) 24 | +dll: $(OBJS) libbz2.def libbz2.res 25 | + link /dll /implib:libbz2.lib /out:libbz2.dll /def:libbz2.def $(OBJS) libbz2.res 26 | 27 | lib: $(OBJS) 28 | lib /out:libbz2-static.lib $(OBJS) 29 | 30 | +bzip2.res: 31 | + $(RC) /fobzip2.res /d BZIP2 version.rc 32 | + 33 | +bzip2recover.res: 34 | + $(RC) /fobzip2recover.res /d BZIP2RECOVER version.rc 35 | + 36 | +libbz2.res: 37 | + $(RC) /folibbz2.res /d LIBBZ2 version.rc 38 | + 39 | test: bzip2 40 | type words1 41 | .\\bzip2 -1 < sample1.ref > sample1.rb2 42 | @@ -54,9 +64,12 @@ clean: 43 | del libbz2.lib 44 | del libbz2.dll 45 | del libbz2.exp 46 | + del libbz2.res 47 | del libbz2-static.lib 48 | del bzip2.exe 49 | + del bzip2.res 50 | del bzip2recover.exe 51 | + del bzip2recover.res 52 | del sample1.rb2 53 | del sample2.rb2 54 | del sample3.rb2 55 | -------------------------------------------------------------------------------- /CHANGES.md: -------------------------------------------------------------------------------- 1 | # Changes 2 | 3 | ## Release v1.0.8.0 - 14-Jul-2019 4 | 5 | - [bzip2 version 1.0.8](https://sourceware.org/ml/bzip2-devel/2019-q3/msg00031.html): 6 | - Accept as many selectors as the file format allows. This relaxes the fix for 7 | CVE-2019-12900 from 1.0.7 so that bzip2 allows decompression of bz2 files 8 | that use (too) many selectors again. 9 | - Fix handling of large (> 4GB) files on Windows. 10 | - Cleanup of bzdiff and bzgrep scripts so they don't use any bash extensions 11 | and handle multiple archives correctly. 12 | - The 05-support_64bit_file_sizes patch has been removed. This has now been 13 | included upstream. 14 | 15 | 16 | ## Release v1.0.7.0 - 28-Jun-2019 17 | 18 | - [bzip2 version 1.0.7](https://sourceware.org/ml/bzip2-devel/2019-q2/msg00022.html): 19 | - Fix undefined behaviour in the macros `SET_BH`, `CLEAR_BH` and `ISSET_BH`. 20 | - bzip2: Fix return value when combining `--test`, `-t` and `-q`. 21 | - bzip2recover: Fix buffer overflow for large `argv[0]`. 22 | - bzip2recover: Fix use after free issue with `outFile` (CVE-2016-3189). 23 | - Make sure `nSelectors` is not out of range (CVE-2019-12900). 24 | 25 | 26 | ## Release v1.0.6.1 - 21-May-2019 27 | 28 | - Visual Studio 2015 is now used to build (instead of Visual Studio 2013). 29 | - The build script has been updated to download from the new bzip2 project home 30 | page at . 31 | - The downloaded file is verified against an expected SHA-256 hash. 32 | - A patch has been applied to allow files larger than 2³² - 1 bytes to be 33 | handled (fixes a 'not a normal file' error). Resolves #3. 34 | 35 | 36 | ## Release v1.0.6 - 1-Feb-2015 37 | 38 | - Initial version of the patches and build script. 39 | - bzip2 version 1.0.6. 40 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Bzip2 – Visual Studio libbz2.dll Build # 2 | 3 | Patches and a PowerShell script to build [bzip2](https://www.sourceware.org/bzip2/) with Visual Studio using a dynamic library (libbz2.dll). 4 | 5 | ## Patches ## 6 | 7 | Patches are included in this repository that modify the `makefile.msc` file in the bzip2 distribution to: 8 | 9 | - Build cleanly with Visual Studio 2013 and later (replacing deprecated command line options). 10 | - Build libbz2 as a DLL (`libbz2.dll`). 11 | - Dynamically link the executable outputs with `libbz2.dll` (by default the executables are statically linked). 12 | - Add a version resource to the executables and DLL. 13 | - Fix a 'not a normal file' error when using `bzip2.exe` to compress large files. 14 | 15 | ## PowerShell Script ## 16 | 17 | The PowerShell script, `Build-Bzip2.ps1`, performs the following actions: 18 | 19 | 1. Downloads the bzip2 source from [https://www.sourceware.org/bzip2/](https://www.sourceware.org/bzip2/). 20 | 2. Extracts and verifies the source. 21 | 3. Applies the patches (see above). 22 | 4. For the x86 and x64 architectures: 23 | 1. Executes `nmake` to build bzip2. 24 | 2. Copies build outputs to a directory named `outputs`. 25 | 3. Creates zipped packages containing build outputs in a directory named `packages`. 26 | 27 | `Build-Bzip2.ps1` requires: 28 | 29 | - 64-bit Windows. 30 | - Microsoft Visual Studio 2013 or later (set `$VisualStudioDir` accordingly). 31 | - [PowerShell Community Extensions](https://pscx.codeplex.com/). 32 | - Git (used to apply patches). 33 | 34 | ## Binaries ## 35 | 36 | 32-bit and 64-bit Windows binaries can be [downloaded from the releases page](https://github.com/philr/bzip2-windows/releases). 37 | 38 | The binary releases depend on the Visual Studio C Runtime Library (please refer to the release notes for details). -------------------------------------------------------------------------------- /Build-Bzip2.ps1: -------------------------------------------------------------------------------- 1 | # Download and build bzip2 for Windows using Visual Studio. 2 | 3 | # Requires Git, PowerShell Community Extensions (https://pscx.codeplex.com/) 4 | # and Visual Studio 2015 on 64-bit Windows. 5 | 6 | Param ( 7 | [string]$GitPath = 'git', 8 | [string]$VisualStudioDir = 'C:\Program Files (x86)\Microsoft Visual Studio 14.0' 9 | ) 10 | 11 | $Version = '1.0.8' 12 | $ExpectedHash = 'AB5A03176EE106D3F0FA90E381DA478DDAE405918153CCA248E682CD0C4A2269' 13 | $PackageVersion = '1.0.8.0' 14 | 15 | $ErrorActionPreference = 'Stop' 16 | 17 | Import-Module -Name 'Pscx' 18 | 19 | # Download bzip2 source if not already in source directory. 20 | $SourceDir = Join-Path -Path $PSScriptRoot -ChildPath 'source' 21 | $GzipFile = "bzip2-$Version.tar.gz" 22 | $GzipPath = Join-Path -Path $SourceDir -ChildPath $GzipFile 23 | 24 | New-Item -ItemType Directory -Force -Path $SourceDir | Out-Null 25 | 26 | if (-not (Test-Path -LiteralPath $GzipPath)) { 27 | Write-Host "Downloading $SourceFile" 28 | Invoke-WebRequest -Uri "https://www.sourceware.org/pub/bzip2/$GzipFile" -Method Get -OutFile $GzipPath 29 | 30 | $ActualHash = Get-FileHash -LiteralPath $GzipPath -Algorithm SHA256 31 | if ($ExpectedHash -ne $ActualHash.Hash) { 32 | throw "Downloaded hash check failed, expected $ExpectedHash, found $($ActualHash.Hash)." 33 | } 34 | } 35 | 36 | # Delete any existing extracted sources and then extract the tar.bz2 file. 37 | $TarFile = ([IO.FileInfo]$GzipFile).BaseName 38 | $TarPath = Join-Path -Path $SourceDir -ChildPath $TarFile 39 | $ExtractedDir = Join-Path -Path $SourceDir -ChildPath (([IO.FileInfo]$TarFile).BaseName) 40 | 41 | if (Test-Path -LiteralPath $TarPath) { 42 | Remove-Item -LiteralPath $TarPath 43 | } 44 | 45 | if (Test-Path -LiteralPath $ExtractedDir) { 46 | Remove-Item -LiteralPath $ExtractedDir -Recurse 47 | } 48 | 49 | Write-Host 'Extracting archive' 50 | 51 | Expand-Archive -LiteralPath $GzipPath -OutputPath $SourceDir -ShowProgress 52 | Expand-Archive -LiteralPath $TarPath -OutputPath $SourceDir -ShowProgress 53 | 54 | Remove-Item -LiteralPath $TarPath 55 | 56 | Push-Location $ExtractedDir 57 | try { 58 | # Copy version.rc resource script, which will be used to add version information to the built DLLs and EXEs. 59 | Copy-Item -LiteralPath (Join-Path -Path $PSScriptRoot -ChildPath 'version.rc') -Destination $ExtractedDir 60 | 61 | # Apply patches from the patches directory. 62 | Write-Host 'Applying patches' 63 | 64 | Get-ChildItem -File -Filter '*.diff' -Path (Join-Path -Path $PSScriptRoot -ChildPath 'patches') | Sort-Object -Property Name | ForEach-Object { 65 | Write-Host "Applying patch $($_.Name)" 66 | 67 | & $GitPath apply -p1 $_.FullName 68 | 69 | if (-not $?) { 70 | throw "Failed to apply patch $($_.Name)" 71 | } 72 | } 73 | 74 | # Setup directories to copy built outputs and packaged zip files to (deleting and recreating if they already exist). 75 | $OutputsRootDir = Join-Path -Path $PSScriptRoot -ChildPath 'outputs' 76 | $OutputsDir = Join-Path -Path $OutputsRootDir -ChildPath $PackageVersion 77 | $PackagesRootDir = Join-Path -Path $PSScriptRoot -ChildPath 'packages' 78 | $PackagesDir = Join-Path -Path $PackagesRootDir -ChildPath $PackageVersion 79 | 80 | New-Item -ItemType Directory -Force -Path $OutputsRootDir | Out-Null 81 | 82 | if (Test-Path -LiteralPath $OutputsDir) { 83 | Remove-Item -LiteralPath $OutputsDir -Recurse 84 | } 85 | 86 | New-Item -ItemType Directory -Force -Path $PackagesRootDir | Out-Null 87 | 88 | if (Test-Path -LiteralPath $PackagesDir) { 89 | Remove-Item -LiteralPath $PackagesDir -Recurse 90 | } 91 | 92 | New-Item -ItemType Directory -Force -Path $PackagesDir | Out-Null 93 | 94 | $VcVarsAllPath = Join-Path -Path (Join-Path -Path $VisualStudioDir -ChildPath 'VC') -ChildPath 'vcvarsall.bat' 95 | 96 | # For both x86 and x64 architectues, build then copy and zip the outputs. 97 | ('x86', 'x86'), ('x64', 'amd64') | ForEach-Object { 98 | $Architecture = $_[0] 99 | $VcVars = $_[1] 100 | 101 | Write-Host "Building $Architecture" 102 | 103 | # Build, using vcvarsall.bat to setup the build environment for the current architecture. 104 | cmd /C "`"$VcVarsAllPath`" $VcVars & nmake -f makefile.msc all" 105 | 106 | if (-not $?) { 107 | throw "Failed to build $Architecture" 108 | } 109 | 110 | # Copy outputs to a directory for the current architecture. 111 | $OutputsArchDir = Join-Path -Path $OutputsDir -ChildPath $Architecture 112 | New-Item -ItemType Directory -Force -Path $OutputsArchDir | Out-Null 113 | 114 | 'libbz2.lib', 'libbz2.dll', 'libbz2.exp', 'libbz2-static.lib', 'bzip2.exe', 'bzip2recover.exe' | ForEach-Object { 115 | Copy-Item -LiteralPath $_ -Destination $OutputsArchDir 116 | } 117 | 118 | # Create zip files containing different sets of files. 119 | ('', ('libbz2.dll', 'bzip2.exe', 'bzip2recover.exe')), ('-dll', ('libbz2.dll')), ('-dev', ('bzlib.h', 'libbz2.lib', 'libbz2.exp', 'libbz2-static.lib')) | ForEach-Object { 120 | $Suffix = $_[0] 121 | $Files = $_[1] 122 | $ZipFile = "bzip2$Suffix-$PackageVersion-win-$Architecture.zip" 123 | 124 | Write-Host "Creating zip $zipFile" 125 | 126 | $Files | Get-Item | Write-Zip -Level 9 -OutputPath (Join-Path -Path $PackagesDir -ChildPath $ZipFile) 127 | } 128 | 129 | # Clean the source tree. 130 | cmd /C "`"$VcVarsAllPath`" $VcVars & nmake -f makefile.msc clean" 131 | 132 | if (-not $?) { 133 | throw "Failed to clean $Architecture" 134 | } 135 | } 136 | } 137 | finally { 138 | Pop-Location 139 | } --------------------------------------------------------------------------------