magento patch failing to install

magento patch failing to install  using -'php,magento,download,patch'

When downloading and running the Magento PHP 5.4 support patch (Magento-CE-v1.7.0.0- from, running the script using sh we receive this error:

$ sh
: command not line 7:
' line 9: syntax error near unexpected token `{
' line 9: `_check_installed_tools() {

Strangely, line 7 of the script is blank (here's the head of the file):

# Patch apllying tool template
# v0.1.2
# (c) Copyright 2013. Magento Inc.

# 1. Check required system tools
_check_installed_tools() {
    local missed=""

We tried the download in Windows and Mac, in Firefox and Chrome to rule out any encoding problems caused by the download process. The patch seems to be very new - Added Jan 17, 2014

We're running Magento Community Edition


We've tried running the .sh file with bash as well but receive the same response.

Interestingly when the click "download", Magento shows the .sh source in the browser so we tried various combinations of view-source then save; copying the text from the browser window and saving it to a text file. None of these solved the problem although one changed the error message to:

$ sh
Checking if patch can be applied/reverted successfully...
/usr/bin/patch: **** malformed patch at line 238:

ERROR: Patch can't be applied/reverted successfully.

Line 238 is the blank comment line here:

+ * Abstract helper class for {@link Zend_Pdf_FileParser} that provides the
+ * data source for parsing.
+ *
+ * Concrete subclasses allow for parsing of in-memory, filesystem, and other
+ * sources through a common API. These subclasses also take care of error
+ * handling and other mundane tasks.

We also tried the VI step mentioned here - :set ff unix

The error then changed to:

$ sh
Checking if patch can be applied/reverted successfully...
ERROR: Patch can't be applied/reverted successfully.

patching file app/code/core/Mage/Catalog/Model/Product.php
Hunk #1 FAILED at 1936.
1 out of 1 hunk FAILED -- saving rejects to file app/code/core/Mage/Catalog/Model/Product.php.rej
patching file app/code/core/Mage/Core/Controller/Varien/Router/Standard.php
Hunk #1 FAILED at 43.
1 out of 1 hunk FAILED -- saving rejects to file app/code/core/Mage/Core/Controller/Varien/Router/Standard.php.rej
patching file app/code/core/Mage/Install/etc/config.xml
patching file app/code/core/Zend/Pdf/FileParserDataSource.php


asked Oct 7, 2015 by sumit_jaiswalmca
0 votes

1 Answer

0 votes

It turns out that this error is given when the patch file (not the file being patched) has line endings which do not match the system on which it is being run.

eg: You will see this error when:

  • You are running on Linux
  • Your patch file has Windows line endings

I changed the patch file to have Unix line endings using Sublime:

View > Line Endings > Unix

See also Error patching Magento 1.7.1 Hunk #1 Failed at

answered Oct 7, 2015 by nimisha.jagtap