preg_match differences in PHP 5.3.2 vs. PHP 5.2.1 - preg-match

Not much of a PHP/regex guy, but am puzzled as to why some functionality in a PHP Web framework has stopped working since moving to Ubuntu 10.04 LTS (PHP 5.3.2) from Ubuntu 8.04 (PHP 5.2.1).
Using xdebug and remote debugging, I was able to step through to a function in a GD library that checks to see if the file in question has a mime type that can thumbnailed:
function liberty_gd_can_thumbnail_image( $pMimeType ) {
$ret = FALSE;
if( !empty( $pMimeType )) {
$ret = preg_match( '/^image/i', $pMimeType );
}
return $ret;
}
I've confirmed that the value of $pMimeType is "i" and changing that line to $ret = true; resolves the issue, but am unsure as to why that would not work now. Hopefully someone with better regex/PHP skills can assist here.

This code is looking for a MIME type that begins with image, e.g. image/gif or image/jpeg. If $pmimeType is "i" then that legitimately fails the test. i is not a valid MIME type, let alone an image MIME type.
I doubt there's anything wrong with the regex matching. I'd look instead at where this bogus i MIME type is coming from.

Related

Increase Max length of image name of Magento 2.3.5 error message:(was not uploaded. Filename is too long; must be 90 characters or less)

When I import product data or I upload image directly to a product I get the following message (was not uploaded. Filename is too long; must be 90 characters or less)
Recently my magento has been updated and I didn't have this problem before.
Does anyone know how I can increase the number of characters slightly?
enter image description here
I was able to solve the problem myself.
The file in question is located in the following folder
vendor\magento\framework\File Uploader.php
search for the following code:
// account for excessively long filenames that cannot be stored completely in database
if (strlen($fileInfo['basename']) > 90) {
throw new \InvalidArgumentException('Filename is too long; must be 90 characters or less');
Adjusting this file is not the best method, I have to add
For anyone finding this question on Google, I wanted to share additional findings, as I've faced the same issue. Perhaps you will find them helpful.
As #Timo already wrote, the limit of 90 characters is hard-coded in the getCorrectFileName() method in vendor\magento\framework\File\Uploader.php (in older versions of Magento).
public static function getCorrectFileName($fileName)
{
(...)
$maxFilenameLength = 90;
if (strlen($fileInfo['basename']) > $maxFilenameLength) {
throw new \LengthException(
__('Filename is too long; must be %1 characters or less', $maxFilenameLength)
);
}
(...)
}
Since this method is static, writing a plugin is not possible and apparently providing a preference won't work as well.
It seems that there was a fix for this already available in Magento, but only in versions 2.4.2 and 2.4.2-p1. Then, for whatever reasons it got removed. See the related Github issue.
Since Magento v2.4.5 the file name length is now limited to 255 characters:
private const MAX_FILE_NAME_LENGTH = 255;
(...)
public static function getCorrectFileName($fileName)
{
(...)
if (strlen($fileInfo['basename'] ?? '') > self::MAX_FILE_NAME_LENGTH) {
throw new \LengthException(
__('Filename is too long; must be %1 characters or less', self::MAX_FILE_NAME_LENGTH)
);
}
(...)
}
So, until you upgrade your Magento version to 2.4.5 or newer, it seems that making a change in the core code is the only option, either manually or using a composer patch.

Using maps in protobuf v2

Currently I am using protobuf version 2 in my project. So far all of the messages are working great; however I have hit a road block trying to use the 'map' keyword.
The TLDR usage behind needing the map, is that I want to pass some JSON key/value pairs to my server to do a lookup, and potential log of data to a server (which uses a JSON message interface).
I am currently using the backwards compatibility method that is recommend on the docs page: https://developers.google.com/protocol-buffers/docs/proto#maps
What I would like to understand is why is the following declaration of my message (using maps) failing to compile? I am using the following veriosn of the protoc compiler: '# protoc --version => libprotoc 2.6.1'
message MapFieldEntry {
optional string key = 1;
optional string value = 2;
}
message Lookup {
repeated MapFieldEntry map_field = 1;
map<string, string> test_map = 2;
}
The error I receive is as follows (the errors don't make sense to me considering the documentation of the map feature):
Expected "required", "optional", or "repeated".
Expected field name.
I have tried adding syntax="proto2"; at the top, but I still get the error.
Edit:
Just as a note; the issue I am having is regarding the second argument of the Lookup message. The first argument is what I am currently using as a work around.
I found someone else with a similar issue on git:
https://github.com/google/protobuf/issues/799
The response is:
The maps syntax is only supported starting from v3.0.0. The "proto2"
in the doc is referring to the syntax version, not protobuf release
version. v3.0.0 supports both proto2 syntax and proto3 syntax while
v2.6.1 only supports proto2 syntax. For all users, it's recommended to
use v3.0.0-beta-1 instead of v2.6.1.
So it looks like to fix your problem, you should use protoc 3, instead of 2.6.1.
And keep your syntax=proto2 at the top of your file to precise this is the proto2 syntax that you use.
Could you try and let me know if this work? this is an interesting question as the official doc does not mention it.

freeimage 3.17 library build failing on Mac OS X: fails with C++11 narrowing error... any ideas?

With not having any understanding of C++ (I'm teaching myself Swift), I'm struggling a bit to get around this one - but ideally would love to be able to expose some of the functionality in the FreeImage library in my project.
It appears that only one module is generating any errors: dcraw_common.cpp - and the lines in error are those from the following entry list where there is a value of 0x80 or above. From the investigations I've done, it would appear that these values are too large for a signed char (max 128?), yet the list also includes negative numbers, and so it can't use an unsigned char.
Any help would be most gratefully received.
Here's an example of the error message generated by the make process:
Source/LibRawLite/./internal/dcraw_common.cpp:4543:19: error: constant expression evaluates to 136 which cannot be narrowed to type 'signed char'
[-Wc++11-narrowing]
+1,-1,+1,+1,0,0x88, +1,+0,+1,+2,0,0x08, +1,+0,+2,-1,0,0x40,
^~~~
And here's the code:
void CLASS vng_interpolate()
{
static const signed char *cp, terms[] = {
-2,-2,+0,-1,0,0x01, -2,-2,+0,+0,1,0x01, -2,-1,-1,+0,0,0x01,
-2,-1,+0,-1,0,0x02, -2,-1,+0,+0,0,0x03, -2,-1,+0,+1,1,0x01,
-2,+0,+0,-1,0,0x06, -2,+0,+0,+0,1,0x02, -2,+0,+0,+1,0,0x03,
-2,+1,-1,+0,0,0x04, -2,+1,+0,-1,1,0x04, -2,+1,+0,+0,0,0x06,
-2,+1,+0,+1,0,0x02, -2,+2,+0,+0,1,0x04, -2,+2,+0,+1,0,0x04,
-1,-2,-1,+0,0,0x80, -1,-2,+0,-1,0,0x01, -1,-2,+1,-1,0,0x01,
-1,-2,+1,+0,1,0x01, -1,-1,-1,+1,0,0x88, -1,-1,+1,-2,0,0x40,
-1,-1,+1,-1,0,0x22, -1,-1,+1,+0,0,0x33, -1,-1,+1,+1,1,0x11,
-1,+0,-1,+2,0,0x08, -1,+0,+0,-1,0,0x44, -1,+0,+0,+1,0,0x11,
-1,+0,+1,-2,1,0x40, -1,+0,+1,-1,0,0x66, -1,+0,+1,+0,1,0x22,
-1,+0,+1,+1,0,0x33, -1,+0,+1,+2,1,0x10, -1,+1,+1,-1,1,0x44,
-1,+1,+1,+0,0,0x66, -1,+1,+1,+1,0,0x22, -1,+1,+1,+2,0,0x10,
-1,+2,+0,+1,0,0x04, -1,+2,+1,+0,1,0x04, -1,+2,+1,+1,0,0x04,
+0,-2,+0,+0,1,0x80, +0,-1,+0,+1,1,0x88, +0,-1,+1,-2,0,0x40,
+0,-1,+1,+0,0,0x11, +0,-1,+2,-2,0,0x40, +0,-1,+2,-1,0,0x20,
+0,-1,+2,+0,0,0x30, +0,-1,+2,+1,1,0x10, +0,+0,+0,+2,1,0x08,
+0,+0,+2,-2,1,0x40, +0,+0,+2,-1,0,0x60, +0,+0,+2,+0,1,0x20,
+0,+0,+2,+1,0,0x30, +0,+0,+2,+2,1,0x10, +0,+1,+1,+0,0,0x44,
+0,+1,+1,+2,0,0x10, +0,+1,+2,-1,1,0x40, +0,+1,+2,+0,0,0x60,
+0,+1,+2,+1,0,0x20, +0,+1,+2,+2,0,0x10, +1,-2,+1,+0,0,0x80,
+1,-1,+1,+1,0,0x88, +1,+0,+1,+2,0,0x08, +1,+0,+2,-1,0,0x40,
+1,+0,+2,+1,0,0x10
}, chood[] = { -1,-1, -1,0, -1,+1, 0,+1, +1,+1, +1,0, +1,-1, 0,-1 };
...
C++11 prevents 'narrowing conversions' like that. Early versions of C++ would accept them. I think this patch to the source of dcraw_common.cpp should fix it.
https://gist.github.com/conchurnavid/ac19c8e882f1835f0310
There's a duplicate question here. Building FreeImage 3.16.0 for Android
The most usable solution I found to this issue was the following GitHub posting: https://github.com/danoli3/FreeImage. Here some kind soul appears to have successfully built the 3.17.0 library and uploaded it. I've found that works just fine.
Please bear in mind however that it's been built with a hard-coded path of /opt/local/lib - which may be an issue when you come to implementation, since your app will be looking for it there, not bundled with the app. I did find this LiveCode post aided my understanding in that regard a lot.
Hope this helps.

Yii2 FileHelper::findFiles() - error with non-ASCII characters

I'm developing an app from the yii2-advanced-app.
In a controller (DocumentController) I read out files in a directory with the FileHelper::findFiles().
It's working, but if my filename contains non-ASCII characters (like the German umlauts, äöü) I only get a question mark in the returning file-path.
How do I solve this? I can't find a suitable answer.
As the web server I'm using IIS 7 on a Windows Server 2008 R2 Enterprise.
DocumentController.php
use yii\helpers\FileHelper;
$data = FileHelper::findFiles($folderPath,['except'=>['*.db']]);
var_dump($data);
The result is:
array(1) { [0]=> string(84) "C:\Websites\dev.point-s.de\space/space_attachments/10082\Aushang 201501 Gr�ndung.pdf" }
The output should be done with the following code, but I think the problem is the reading of the files.
Html::a($model['name'], ['document/download', 'file' => $model['name']])
OK thanks #ineersa for trying to help, I got the answer with help from my coworker.
The solution is to explicit convert the filename returned by findFiles() to UTF-8 with the PHP function utf8_encode()
http://php.net/manual/en/function.utf8-encode.php

wxFileExists returns false in Mac

I am using wxWidgets in Mac with C++ (obviously) and Xcode.
This line returns false, when it should be true.
` if(!wxFileExists(filePicker->GetPath())
{
wxMessageDialog(this, "error").ShowModal();
return;
} `
where filePicker is a wxFilePickerCtrl. It's value is :
filepath std::__1::string "/Users/swtsvn/Main/Proj1/Mac/binaries/osx/Debug/wxSampleApp.app"
The path has upper case, and no spaces. The File is located in that path, since I picked that file path using file picker wxWidget tool.
I searched for a reason wxFileExists might return false on Mac but not on Windows, but could not find one in Google.
If anyone knows the answer, kindly let me know.
According to the docs, wxFileExists():
Returns true if the file exists and is a plain file.
So, it returns false for directories. Mac app bundles, such as your wxSampleApp.app, are directories. It is the intentional behavior of the function that it return false in this case.
You could presumably use wxFileExists(path) || wxDirExists(path) instead, although that will be somewhat inefficient.

Resources