kangax/fabric.js — pull request #531 by shiloa (2013-04-03 11:11:20+00:00)
Title: Application crashes (segfault) on node.js if canvas loads images that secure url (https://...)

## Synopsis
Using node, try to render a canvas (from previously stored `canvas.toJSON()` data). If that JSON contains an image with src that comes from https url, the node application crashes with segmentation fault when running `canvas.loadFromJSON`. No stack trace is provided.

## How to reproduce

Run this (using fabric.js/dist/all.js from d60b07574cc91f9526a57513529ce9460ce48e7e or earlier):

```javascript
var fabric = require('fabric').fabric;

var TEST_JSON = {
"objects": [
{
"type": "image",
"left": 300,
"top": 100,
"width": 275,
"height": 95,
"fill": "rgb(0,0,0)",
"overlayFill": null,
"stroke": null,
"strokeWidth": 1,
"strokeDashArray": null,
"scaleX": 1,
"scaleY": 1,
"angle": 0,
"flipX": false,
"flipY": false,
"opacity": 1,
"selectable": true,
"hasControls": true,
"hasBorders": true,
"hasRotatingPoint": false,
"transparentCorners": true,
"perPixelTargetFind": false,
"src": "https://stripe.com/img/frontpage/blueprints.png",
"filters": []
}], "background": "rgba(0, 0, 0, 0)"
};

var canvas = fabric.createCanvasForNode(500, 500);
canvas.loadFromJSON(TEST_JSON, function(){ /* segmentation fault */ });
```
## Crash source and fix
After some digging, the source of the problem seemed to be how the built in [request](https://github.com/kangax/fabric.js/blob/master/dist/all.js#L17211) handler that uses node's `http` module. By substituting the `http` module with the `https` one for secure connections, everything seems to work as expected.

## Notes

This is a proposed solution that solved a specific problem I was having (trying to render a PNG image from canvas' JSON having most of its images with secure urls). I noted that if I used `https://www.google.com/images/logo.png` to test, the above code didn't segfault. However, this could be because google also has the same link work without https (`http://www.google.com/images/logo.png`). I didn't dig any deeper than that.

Also, sorry for not adding any tests. I did make sure this didn't break any of the existing ones (same failures as before changes). I'd love some suggestions on how properly test this in coherence with the existing test suite.